题解 | #列出供应商及其可供产品的数量#
列出供应商及其可供产品的数量
http://www.nowcoder.com/practice/17f22851cf204019b51a36761a3afc79
vend_id在两个表中都有,为了避免计算机无法识别,需要在前面加上表名 prod_id中含有0,说明含有vend_id的表是主表 两个表中都含有vend_id,通过和答案示例比较,我们发现Vendors是主表
select v.vend_id, ifnull(prod_id, 0) prod_id
from Vendors v
left join
(
select vend_id, count(*) prod_id
from Products group by vend_id
) p
on v.vend_id = p.vend_id
order by vend_id;