谁会用sql语句 找分组中的 随机记录是这样分组 记录
 a     1
 a     2
 a     3
 b     1
 b     2
 c     6
 c     7
 d     4
 d     3我想找出 这样的记录 a    (从现有的123中随机找一个 )
b    (从现有的12中随机找一个 )
c    (从现有的67中随机找一个 )
d    (从现有的34中随机找一个 )不知道我说清楚没有。想半天没想现来。 求高人 来指点一下 

解决方案 »

  1.   

    select * from yourTable A where 记录=(select top 1 记录 from yourTable where 分组=A.分组 order by newid()) order by 分组
      

  2.   

    select distinct * from yourTable A where 记录=(select top 1 记录 from yourTable where 分组=A.分组 order by newid()) order by 分组
      

  3.   

    加distinctselect distinct * from yourTable A where 记录=(select top 1 记录 from yourTable where 分组=A.分组 order by newid()) order by 分组