欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

sqlserver中重復(fù)數(shù)據(jù)值只取一條的sql語句

 更新時間:2012年05月27日 23:21:36   作者:  
sqlserver中有時候我們需要獲取多條重復(fù)數(shù)據(jù)的一條,需要的朋友可以參考下面的語句
復(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
)

相關(guān)文章

最新評論