怎样判断某个字段在记录集里是重复的?sql语句

jcaomao 2003-05-11 02:11:26
如:

字段1 字段2 字段3
aa bb cc
a1 b1 c1
a2 b1 c2

就是怎样挑出来 字段2中 第二条和第三条中的字段2都为b1 的所有记录
...全文
15 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
caiyunxia 2003-05-11
SELECT * FROM # ID IN(
(SELECT ID FROM # A WHERE EXISTS(SELECT * FROM # WHERE 字段2 =A.字段2 AND ID=A.ID -1))
UNION SELECT * FROM # ID IN(
(SELECT ID -1 FROM # A WHERE EXISTS(SELECT * FROM 字段2 =A.字段2 AND ID=A.ID -1))
回复
caiyunxia 2003-05-11
字段2 有重复的记录
select * from 表 where 字段2 in (select 字段2 from 表 group by 字段2 having count(*)>1)

连续两条字段2 重复的记录

SELECT IDENTITY(INT,1,1) AS ID,* INTO # FROM TABLE

SELECT * FROM # ID IN(
(SELECT ID FROM # A WHERE EXISTS(SELECT * FROM # WHERE 字段2 =A.字段2 AND ID=A.ID -1))
UNION ALL
SELECT * FROM # ID IN(
(SELECT ID -1 FROM # A WHERE EXISTS(SELECT * FROM 字段2 =A.字段2 AND ID=A.ID -1))
回复
caiyunxia 2003-05-11
连续两条字段2 重复?
还是字段2 有重复的记录
回复
jcaomao 2003-05-11
对不起,我没有说清楚,我不知道字段2某条记录的确定值。

就想查出有哪些记录在字段2处有重复。
回复
pengdali 2003-05-11
select * from 表 where bb in (select bb from 表 group by bb having count(*)>1)
回复
caiyunxia 2003-05-11
select * from table where 字段2='b1'
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-11 02:11
社区公告
暂无公告