我需要在单个MYSQL查询中列出所有重复ID以及每个ID的出现次数。
ID
____
1
1
2
3
4
4
4
5
5
6
7
输出必须是:
ID | Occurrence
_______________
1 | 2
4 | 3
5 | 2
答案 0 :(得分:0)
只需使用简单的GROUP BY
查询:
SELECT ID, COUNT(*) AS Occcurrence
FROM yourTable
GROUP BY ID
HAVING COUNT(*) > 1
答案 1 :(得分:0)
select
Id, count(id) as Occurance
from
tableName
group by id
having Occurance > 1;
答案 2 :(得分:0)
使用mysql GROUP BY
select ID,count(*) from table_name group by ID having count(*) > 1