比如表里有个字段 c1,里面是多个可能有重复的值,例如
1001
1002
1001
1003
1002
1003
……
这样的
现在我想用 select top 1 * from tb where c1 in (……)的方式,把每个c1值的第一个记录给取出来。该怎么写?
1001
1002
1001
1003
1002
1003
……
这样的
现在我想用 select top 1 * from tb where c1 in (……)的方式,把每个c1值的第一个记录给取出来。该怎么写?
select * from cte where pid=1
select top 1 c1 from table1 group by c1 order by count(1) desc
所有记录
select top 1 * from table1 as a order by (select count(1) from table1 where c1=a.c1) desc