内容如下:
glbm id
001 1
024 2
026 3
028 3
036 4
...
...
我想把id值相同的记录筛选出来,该怎么写SQL语句?
谢谢大家了!!!
8 个解决方案
#1
select * from 表 where id in(select count(*) from 表 having count(*)>1)
#2
to songyangk(小草):
不对吧,按你这样写的结果不就成了select * from 表 where id in (2)了吗?
不对吧,按你这样写的结果不就成了select * from 表 where id in (2)了吗?
#3
不好意思,写错了。
select * from 表 where id in(select id,count(*) from 表 group by ID having count(*)>1)
select * from 表 where id in(select id,count(*) from 表 group by ID having count(*)>1)
#4
select * from 表 where id in (select id from 表 group by id having count(*)>1)
#5
不好意思,写错了
SELECT * FROM 表 WHERE id IN (SELECT id FROM 表 GROUP BY id HAVING COUNT(*) 1)
SELECT * FROM 表 WHERE id IN (SELECT id FROM 表 GROUP BY id HAVING COUNT(*) 1)
#6
再说清楚一点,选出来后做什么
是不是把相同ID号大于2的记录提出来?
select * from YourTable where Id in (
(select Id from YourTable group by Id having count(Id)>1))
是不是把相同ID号大于2的记录提出来?
select * from YourTable where Id in (
(select Id from YourTable group by Id having count(Id)>1))
#7
select * from YourTable where id
in (select Distinct id from YourTable group by id having count(*)>1 )
order by id
in (select Distinct id from YourTable group by id having count(*)>1 )
order by id
#8
select *
from table
where table(id)=txt.text
from table
where table(id)=txt.text
#1
select * from 表 where id in(select count(*) from 表 having count(*)>1)
#2
to songyangk(小草):
不对吧,按你这样写的结果不就成了select * from 表 where id in (2)了吗?
不对吧,按你这样写的结果不就成了select * from 表 where id in (2)了吗?
#3
不好意思,写错了。
select * from 表 where id in(select id,count(*) from 表 group by ID having count(*)>1)
select * from 表 where id in(select id,count(*) from 表 group by ID having count(*)>1)
#4
select * from 表 where id in (select id from 表 group by id having count(*)>1)
#5
不好意思,写错了
SELECT * FROM 表 WHERE id IN (SELECT id FROM 表 GROUP BY id HAVING COUNT(*) 1)
SELECT * FROM 表 WHERE id IN (SELECT id FROM 表 GROUP BY id HAVING COUNT(*) 1)
#6
再说清楚一点,选出来后做什么
是不是把相同ID号大于2的记录提出来?
select * from YourTable where Id in (
(select Id from YourTable group by Id having count(Id)>1))
是不是把相同ID号大于2的记录提出来?
select * from YourTable where Id in (
(select Id from YourTable group by Id having count(Id)>1))
#7
select * from YourTable where id
in (select Distinct id from YourTable group by id having count(*)>1 )
order by id
in (select Distinct id from YourTable group by id having count(*)>1 )
order by id
#8
select *
from table
where table(id)=txt.text
from table
where table(id)=txt.text