SQL90. 纠错3
描述
order_num |
a002 |
a002 |
a002 |
a004 |
a007 |
SELECT order_num, COUNT(*) AS items FROM OrderItems GROUP BY items HAVING COUNT(*) >= 3 ORDER BY items, order_num;【示例结果】
order_num | items |
a002 | 3 |
示例1
输入:
DROP TABLE IF EXISTS `OrderItems`; CREATE TABLE IF NOT EXISTS `OrderItems`( order_num VARCHAR(255) NOT NULL COMMENT '商品订单号' ); INSERT `OrderItems` VALUES ('a002'),('a002'),('a002'),('a004'),('a007');
输出:
a002|3
Mysql 解法, 执行用时: 39ms, 内存消耗: 6412KB, 提交时间: 2022-03-04
SELECT order_num, COUNT(order_num) AS items FROM OrderItems GROUP BY order_num HAVING items >= 3 ORDER BY items, order_num;
Mysql 解法, 执行用时: 39ms, 内存消耗: 6500KB, 提交时间: 2022-03-03
SELECT order_num, COUNT(*) AS items FROM OrderItems GROUP BY order_num HAVING items >= 3 ORDER BY items, order_num;
Mysql 解法, 执行用时: 39ms, 内存消耗: 6596KB, 提交时间: 2022-03-03
SELECT order_num, COUNT(*) AS items FROM OrderItems GROUP BY order_num HAVING items >= 3 ORDER BY items, order_num;
Mysql 解法, 执行用时: 40ms, 内存消耗: 6432KB, 提交时间: 2022-03-04
SELECT order_num,COUNT(*) AS items FROM OrderItems GROUP BY order_num HAVING COUNT(*) >= 3 ORDER BY items, order_num;
Mysql 解法, 执行用时: 40ms, 内存消耗: 6436KB, 提交时间: 2022-03-05
select order_num, count(order_num) as items from OrderItems group by order_num having items >= 3 order by items, order_num