久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SQL Server數據庫多種方式查找重復記錄

瀏覽:200日期:2023-11-05 10:06:46
SQL Server數據庫多種方式查找重復記錄:

示例:表stuinfo,有三個字段recno(自增),stuid,stuname

建該表的Sql語句如下:

CREATE TABLE [StuInfo] (

[recno] [int] IDENTITY (1, 1) NOT NULL ,

[stuid] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,

[stuname] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL

) ON [PRIMARY]

GO

1.查某一列(或多列)的重復值(只可以查出重復記錄的值,不能查出整個記錄的信息)

例如:查找stuid,stuname重復的記錄

select stuid,stuname from stuinfo

group by stuid,stuname

having(count(*))>1

2.查某一列有重復值的記錄(此方法查出的是所有重復的記錄,如果有兩條記錄重復的,就查出兩條)

例如:查找stuid重復的記錄

select * from stuinfo

where stuid in (

select stuid from stuinfo

group by stuid

having(count(*))>1

)

3.查某一列有重復值的記錄(只顯示多余的記錄,也就是說如果有三條記錄重復的,就顯示兩條)

前提:需有一個不重復的列,此示例為recno。

例如:查找stuid重復的記錄

select * from stuinfo s1

where recno not in (

select max(recno) from stuinfo s2

where s1.stuid=s2.stuid

標簽: Sql Server 數據庫
主站蜘蛛池模板: 铜陵市| 昆明市| 井冈山市| 阜南县| 山阳县| 晋中市| 兴宁市| 阳高县| 稷山县| 平山县| 博野县| 昌黎县| 南川市| 镇巴县| 荥经县| 政和县| 南昌县| 东丰县| 台北市| 盐津县| 河东区| 峨眉山市| 梧州市| 怀来县| 南汇区| 博罗县| 甘孜县| 石林| 方正县| 孟连| 交城县| 广水市| 梁河县| 永善县| 苍溪县| 大邑县| 惠水县| 象州县| 宣恩县| 金坛市| 宝鸡市|