本学渣就是学了好久不用又忘,今天面试人家问我having我都忘了
法1:having
先将准备筛选的重复数据用group 进行分组,再进行过滤
---统计号码重复下单次数
SELECT transact_billid, COUNT(transact_billid)
FROM table
group by transact_billid
HAVING COUNT(transact_billid) > 1
法2:用 PARTITION BY进行分组
COUNT(*)OVER: 对于查询结果的每一行都返回所有符合条件的行的条数
SELECT touch_channel_code, transact_billid
FROM (SELECT touch_channel_code, transact_billid, COUNT(*) OVER(PARTITION BY transact_billid) AS cnt
FROM order_app.td_customer_order_202305)--统计所有 transact_billid 次数
WHERE cnt > 1;