题解 | #返回每个订单号各有多少行数#
返回每个订单号各有多少行数
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;