SQL 救命!!!!!!

angel6709 2009-11-20 09:57:21
假设有一个表
TabA(id int)

里面数据如下:
id
0
1
2
3
4
5
6
7
7

8
9
10
11
12
12

13
...

怎么查询出id重复的数据???
即,想要的结果为:

id
7
12
...全文
166 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
知识与运气 2009-11-20
  • 打赏
  • 举报
回复
可以列出每一个数有几个重复的
select id,count(*) as c from TabA group  by id order by c desc


查询出重复的记录
select distinct(id) from TabA where id in  (select id from TabA group by id having count(*)>1) 

cx419075909 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lzsh0622 的回复:]
思路:
select * from tb where id in select count(id)>1
[/Quote]

就酱紫滴
angel6709 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 qldsrx 的回复:]
这个我经常做,可以说是非常简单的问题:
C# codeselect idfrom TabAgroupby id
having count(1)>1
[/Quote]
结贴。。。。
雷肿么了 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 qldsrx 的回复:]
这个我经常做,可以说是非常简单的问题:
C# codeselect idfrom TabAgroupby id
having count(1)>1
[/Quote]

这个真不错
wangfeizjk 2009-11-20
  • 打赏
  • 举报
回复
SELECT count(id) aa,id FROM TabA GROUP BY id HAVING count(id)>1 ORDER BY aa
dqw120 2009-11-20
  • 打赏
  • 举报
回复
select distinct id from 表名
distinct是过滤掉重复的记录
Hiro_chen 2009-11-20
  • 打赏
  • 举报
回复
顶下
mohugomohu 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ronxh 的回复:]
引用 2 楼 lzsh0622 的回复:
思路:
select * from tb where id in select count(id)>1

顶!
[/Quote]1
tkscascor 2009-11-20
  • 打赏
  • 举报
回复
up 4l
沉默味道ron 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lzsh0622 的回复:]
思路:
select * from tb where id in select count(id)>1
[/Quote]
顶!
qldsrx 2009-11-20
  • 打赏
  • 举报
回复
啊,用错了格式,应该是SQL格式,不小心用了C#格式,那个是SQL语句哦
ljhcy99 2009-11-20
  • 打赏
  • 举报
回复
select id,count(id)
from table
group by id
having count(id)>1
qldsrx 2009-11-20
  • 打赏
  • 举报
回复
这个我经常做,可以说是非常简单的问题:

select id from TabA
group by id
having count(1)>1
angel6709 2009-11-20
  • 打赏
  • 举报
回复
补充一下。是Sqlserver2005的
哎,没有办法呀,当时没有设主键,现在里面好多东东。插入速度越来越。。。
但是里面有那么几条同样id的数据。。。。。。。key不上去。
lzsh0622 2009-11-20
  • 打赏
  • 举报
回复
思路:
select * from tb where id in select count(id)>1
lee_b 2009-11-20
  • 打赏
  • 举报
回复

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧