题解 | #返回产品名称和每一项产品的总订单数#

返回产品名称和每一项产品的总订单数

https://www.nowcoder.com/practice/1c64fd9048364a58a8ffa541720359a4

select prod_name, count(order_num) orders
from Products a left join OrderItems b
on a.prod_id = b.prod_id
group by prod_name
order by prod_name;








-- 下面的不行,会显示none
select prod_name, orders
from Products a left join (
    select count(order_num) orders,prod_id
    from OrderItems
    group by prod_id
) b on a.prod_id = b.prod_id
order by prod_name;




select count(order_num) orders
from OrderItems
group by prod_id;

全部评论

相关推荐

dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
评论
1
1
分享
牛客网
牛客企业服务