题解 | #返回产品名称和每一项产品的总订单数#
返回产品名称和每一项产品的总订单数
https://www.nowcoder.com/practice/1c64fd9048364a58a8ffa541720359a4
select p.prod_name,ifnull(x.orders,0). #用ifull去将null改成0
from Products as pleft join (select prod_id,count(prod_id) as orders from OrderItems group by prod_id) as x
on x.prod_id = p.prod_id
order by p.prod_name;