【发布时间】:2020-11-03 04:20:33
【问题描述】:
我有两个表“cats_lables”和“classified_cats”,在“cats_lables”表中我只能添加一个新的猫类/标签。然后我可以使用这个类/标签对新猫进行分类并将它们添加到“分类猫”表中。
所以表格是这样的:
cats_lables:
id cats_lable
1 Polydactyl
2 Snowshoe
3 Calico
classified_cats:
id class_id cat_age placeOfBorn cat_price
1 1 3 months Eygipt 1000
2 3 6 months Lebanon 2000
所以,这是只显示已分类猫的查询:
SELECT "cats_lables".*,
CAST(COUNT("classified_cats"."class_id") AS int) AS class_count
FROM "Labels"
INNER JOIN "classified_cats"
ON "classified_cats"."class_id"="cats_lables"."id"
GROUP BY "cats_lables"."id"
ORDER BY class_count DESC
但我想升级我的查询以显示猫类,即使没有分配给它的猫。
如何解决我的查询问题?
【问题讨论】:
-
左连接........
-
谢谢@MitchWheat,这是它????????。
标签: sql database inner-join