简单计数Mysql查询

时间:2012-10-12 18:58:26

标签: mysql count

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

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

2 个答案:

答案 0 :(得分:3)

您只需要一个GROUP BY

的聚合函数
select order_id
from yourtable
group by order_id
having count(order_id) > 1

请参阅SQL Fiddle with Demo

答案 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