我想获取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
请帮忙。提前谢谢。
答案 0 :(得分:6)
select * from your_table
where organization_no in
(select organization_no
from your_table
group by organization_no
having count(*) > 1)
答案 1 :(得分:0)
SELECT * FROM table t
WHERE organisation_no IN
(SELECT organisation /*from the solution you have found*/)