在同一个表列中选择重复的记录并将它们列出
问题描述:
我已经搜索,但到目前为止没有找到答案适合我的情况。在同一个表列中选择重复的记录并将它们列出
你如何写选择语句来选择在同一个表列中的重复记录,并列出它们(所以不是由它组)?
例如:找到contract_id列重复,并一一列举出来
ID contract_id Sales1 Sales2
1 12345 100 200
2 54321 300 674
3 12345 343 435
4 09876 125 654
5 54321 374 233
6 22334 543 335
结果应该由contract_id像这样与顺序,以及:
ID contract_id Sales1 Sales2
1 12345 100 200
3 12345 343 435
2 54321 300 674
5 54321 374 233
答
你可以在数使用子查询> 1
select * from my_table
where contract_id in (
select contract_id
from my_table
group by contract_id
having count(*) > 1
)
赞赏它,它工作正常 –
@StevenHuang好,如果我的回答是正确的请将其标记为已接受...看到这里如何 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – scaisEdge
对不起,不知道如何接受答案到现在。我已选择“检查”以获得答案。感谢您的回答! –