select t.prod_name,count(order_num) as order_num from Products t left join OrderItems t1 on t.prod_id = t1.prod_id group by t.prod_name order by t.prod_name
易错点:
因为Products表中有产品没有订单,所以求数量的时候
不能使用count(),必须使用count(order_num) 使用count
即使有null值,也会算一行
select t.prod_name,count(order_num) as order_num from Products t left join OrderItems t1 on t.prod_id = t1.prod_id group by t.prod_name order by t.prod_name
易错点:
因为Products表中有产品没有订单,所以求数量的时候
不能使用count(),必须使用count(order_num) 使用count
即使有null值,也会算一行