我想在sql中获取所有重复的值。我找了很多地方,但没有得到我想要的。我的桌子是这样的:
company_id | supplier_id | company_name | organisation_no | type | sold_date
----------------------------------------------------------------------------
121234 | 934575 | fgdf | 12345 | sold | 2011-12-2
214365 | 423234 | sdgd | 5678 | sold | 2011-12-2
546534 | 234234 | bvcv | 3333 | sold | 2011-12-2
276345 | 243324 | dfgd | 12345 | sold | 2011-12-2
432642 | 567647 | ghmj | 12345 | sold | 2011-12-2
846578 | 365356 | egff | 3333 | sold | 2011-12-2
254334 | 346535 | yuuy | 7890 | sold | 2011-12-2
我找到的解决方案是这样的:
organisarion_no | count(organisation_no)
----------------------------------------
3333 | 2
12345 | 3
但我想要这样:
company_id | supplier_id | company_name | organisation_no | type | sold_date
----------------------------------------------------------------------------
546534 | 234234 | bvcv | 3333 | sold | 2011-12-2
846578 | 365356 | egff | 3333 | sold | 2011-12-2
121234 | 934575 | fgdf | 12345 | sold | 2011-12-2
276345 | 243324 | dfgd | 12345 | sold | 2011-12-2
432642 | 567647 | ghmj | 12345 | sold | 2011-12-2
请帮忙。提前谢谢。
最佳答案
select * from your_table
where organization_no in
(select organization_no
from your_table
group by organization_no
having count(*) > 1)
关于mysql - 在SQL中获取所有重复的行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6289709/