receipt_id order_id
1 A
2 B
3 B
4 C
5 C
显示此表中order_id的计数大于1的所有记录的sql代码是什么?
答案 0 :(得分:3)
您只需要一个GROUP BY
select order_id
from yourtable
group by order_id
having count(order_id) > 1
答案 1 :(得分:1)
试试这个:
Select * from table where order_id in (select distinct order_id
from table
group by order_id
having count(order_id) > 1)
<强> DEMO 强>