我有一张表格,其中包含特定车型所需的所有零件:
CarBuild
-id
-model
-partId
因此,要获得模型的所有部分,您将会这样做:
select * from CarBuild where model=f150
CarProgress目前正在制造汽车以及已安装的部件。
CarProgress
-model
-partId
如何查询所有缺少按模型分组的零件的汽车进度车?
到目前为止,我有以下查询,我应该做左外连接吗?
select *
from carprogress cp
inner join carbuild cb on cp.model = cb.model
如果有人能向我解释他们理想的解决方案。
答案 0 :(得分:0)
select cb.model, count(*)
from carbuild cb left outer join carprogress cp
on cp.model = cb.model
where cp.model is null
group by cb.model