题解 | #返回每个订单号各有多少行数#

返回每个订单号各有多少行数

http://www.nowcoder.com/practice/cf1f8d4a514d455aa0468718fb411f41

  • 先执行GROUP BY order_num,对所有记录分组,分为三组,
  • 再执行SELECT order_num, COUNT(order_num) AS order_lines
  • 最后执行ORDER BY order_lines ASC;对结果进行排序
SELECT order_num, COUNT(order_num) AS order_lines
FROM OrderItems
GROUP BY order_num
ORDER BY order_lines ASC;
全部评论

相关推荐

喜欢吃蛋糕仰泳鲈鱼是我的神:字节可以找个hr 给你挂了,再放池子捞
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务