求教MSSQL分组后每组随机取出一条数据如何写,要随机取的.

求教MSSQL分组后每组随机取出一条数据怎么写,要随机取的..
字段1 字段2
id  name
1   a
2   b
3   c
4   c
5   b
根据name分组,最后每组随机取出一条数据。

求教MSSQL分组后每组随机取出一条数据如何写,要随机取的.网上有许多类似的代码,但是运行有问题啊

MS SQL 分组后随机取出数据

------解决方案--------------------
改一下6楼的代码,这样可以随机,但是在数据量大的时候才容易随机
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