简体   繁体   中英

SQL 3 table Join While taking all values from 1 table but only filled from other 2

I have three tables: the first has a list of category IDs, the second has dataset information, and the third has import information.

What I have

select dataset.pc_id , count(*) 
from import 
join dataset on CAST (dataset.internal_id as varchar(20)) = import.product_id 
group by dataset.pc_id,  order by pc_id asc

This will output:

3 4

4 5

6 200

7 192

8 1000

Where product_category comes into play is this: I want the output to look like:

1 0

2 0

3 4

4 5

6 200

...

16 0

The 16 are the number of different product categories from the product_category table that I currently cannot figure out how to fit into that statement.

What is the way to get all the id's from product category into this list with the information joined occupying the result?

弄清楚了,需要摆脱选择dataset.pc_id的问题,只需要选择product_category.id,然后右键加入product_category。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM