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;