我的表中有名为 application_id 的列,它包含如下值
32,
65,
75,
75,
32,
45,
56,
78,
64
我只想获取重复的值
像 75,32
我认为它与不同的有点相反。我不知道怎么办?
如果您只想选择,application_id
那么只需使用@Sayonji已经建议的查询
SELECT application_id FROM MyTable GROUP BY application_id HAVING count(*) > 1
但是,如果要选择所有列,则可以使用子查询来实现:
SELECT DISTINCT * FROM MyTable
WHERE application_id IN
(
SELECT application_id FROM MyTable
GROUP BY application_id
HAVING COUNT(*) > 1
);
或使用自联接:
SELECT DISTINCT t1.* FROM MyTable t1
JOIN
(
SELECT application_id FROM MyTable
GROUP BY application_id
HAVING COUNT(*) > 1
) t2
ON t1.application_id = t2.application_id;
就像是
SELECT a_id FROM mytable GROUP BY a_id HAVING count(a_id) > 1