復(fù)制代碼 代碼如下:
--建立數(shù)據(jù)表createtable TestData
(
ID int identity(1,1) primary key,
Data int,
ColA varchar(20),
ColB varchar(20)
)
go
--插入測試數(shù)據(jù)
declare @counts int
declare @i int
set @counts = 10000
set @i = 1
while @i=@counts
begin
insert TestData (Data,ColA,ColB) values(cast(rand()*10000 as int),cast(rand() as varchar(20)),cast(rand() as varchar(20)))
set @i=@i+1
end
--獲取數(shù)據(jù)(重復(fù)數(shù)據(jù)只取一條)
select * from TestData
where
id in
(
--根據(jù)Data分類獲取數(shù)據(jù)最小ID列表
select min(id) from TestData
group by Data
)
您可能感興趣的文章:- SQL Server數(shù)據(jù)庫刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實(shí)例講解
- Sql Server使用cursor處理重復(fù)數(shù)據(jù)過程詳解
- sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法
- sqlserver合并DataTable并排除重復(fù)數(shù)據(jù)的通用方法分享
- 教你幾種在SQLServer中刪除重復(fù)數(shù)據(jù)方法
- MSSql簡單查詢出數(shù)據(jù)表中所有重復(fù)數(shù)據(jù)的方法