我可以计算一次使用折扣代码多次的订单吗?
from functools import reduce
所以我希望它重新带回订单:151和161
Order Codes
123 mowerwo
151 femorfm
151 geirmgr
151 rtert
161 erger
161 wefww
162 wweff
答案 0 :(得分:0)
您可以执行以下操作:
SELECT order_num
FROM orderdiscount
GROUP BY discountcode
HAVING COUNT (*) > 1;
如果仅需要代码,则无需进行不必要的计数
答案 1 :(得分:0)
您需要将所有列包括在select
和group by
列表(此处为order_num
)中,这不是诸如 sum之类的聚合函数,计数,平均等
count(*)
或count(1)
或count(0)
或count(order_num)
都给出相同的结果。
请使用:
SELECT order_num, count(1) as discount
FROM ordersdiscount
GROUP BY order_num
HAVING count(1)>1;
order_num discount
151 3
161 2