题解 | #纠错3#
纠错3
http://www.nowcoder.com/practice/3870c9bca7a4406f899af3e903b8bf51
- 先执行GROUP BY order_num,对所有字段按照order_num 分组,
- 再执行HAVING items >= 3,对分组进行过滤,即查询出满足items大于等于3的记录,
- 再执行SELECT order_num, COUNT(order_num) AS items,
- 最后执行ORDER BY items, order_num;对记录进行排序,默认是升序。
SELECT order_num, COUNT(order_num) AS items
FROM OrderItems
GROUP BY order_num
HAVING items >= 3
ORDER BY items, order_num;
附DQL执行顺序