復制代碼 代碼如下:
--建立數據表createtable TestData
(
ID int identity(1,1) primary key,
Data int,
ColA varchar(20),
ColB varchar(20)
)
go
--插入測試數據
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
--獲取數據(重復數據只取一條)
select * from TestData
where
id in
(
--根據Data分類獲取數據最小ID列表
select min(id) from TestData
group by Data
)