日期:2014-05-17 浏览次数:20475 次
create table t
(
id int,
name varchar(10)
)
insert into t
select 1,'a' union
select 2,'b' union
select 3,'c' union
select 4,'c' union
select 5,'b'
select t.name,(SELECT TOP 1 id FROM t a WHERE a.NAME=t.NAME ORDER BY CHECKSUM(NEWID()))id
from t
group by t.name
drop table t
create table t
(
id int,
name varchar(10)
)
insert into t
select 1,'a' union
select 2,'b' union
select 3,'c' union
select 4,'c' union
select 5,'b'
select t.name,(SELECT TOP 1 id FROM t a WHERE a.NAME=t.NAME ORDER BY RAND()*100)id
from t
group by t.name
--RAND()*100 100为一个基数根据本身id列值得范围进行修改
drop table t