| |

VerySource

 Forgot password?
 Register
Search
View: 864|Reply: 6

Finding a SQL statement that is not difficult

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-11 13:30:01
| Show all posts |Read mode
2 tables, 1 is the parts list bj (one field represents the part code and one field is the flag tag), and 1 is the price list jg (there is also a part code field and a price field)

Now find the price of all parts whose flag is true.

select bj.id, jg.jg from bj, jg where bj.flag = 1

The problem is that in the price list, the prices of some parts do not exist. According to the above query, only the parts that exist in both tables are available, but I cannot get a list of all parts with flag = 1.

The requirement is to get a list of all parts with flag = 1. If any part does not exist in the price list, it will automatically take 0.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-4 08:45:01
| Show all posts
select bj.id,jg.jg from bj,jg where bj.flag=1 and bj.id=jg.id
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-6 15:00:01
| Show all posts
select bj.id
       ISNULL(jg.jg,0)
left join jg on bj.id=jg.id
where bj.flag=1
Reply

Use magic Report

1

Threads

21

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 Great Britain

Post time: 2020-6-18 08:00:01
| Show all posts
select bj.id,jg.jg from bj left outer join jg on bj.id=jg.id where bj.flag=1

bj.id=jg. Part code field after on (if id is part id column)
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-4 17:30:02
| Show all posts
Positive solution on the first floor
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-24 08:00:01
| Show all posts
I did it myself, and it was very complicated. I used union, and set the price of the parts already in the price list + the price of the parts that did not exist in the price list to 0.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

Post time: 2020-7-28 17:00:01
| Show all posts
SELECT bj.id,IsNull(jg.jg,0)
FROM bj,jg
WHERE bj.id=jg.id(+) and bj.flag=1
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list