0
receipt_id           order_id
1                       A
2                       B
3                       B
4                       C
5                       C

显示该表中order_id计数大于1的所有记录的sql代码是什么?

4

2 回答 2

3

你只需要一个聚合函数GROUP BY

select order_id
from yourtable
group by order_id
having count(order_id) > 1

请参阅带有演示的 SQL Fiddle

于 2012-10-12T18:59:31.977 回答
1

试试这个:

 Select * from table where order_id in (select  distinct order_id
 from table
 group by order_id
 having count(order_id) > 1)

演示

于 2012-10-12T19:00:22.723 回答