表a
id    active
1       xx
1       xx
2       xx
3       xx
.....
如上表,已知有多个id(上表中的id肯定在已知id中),我想知道id出现最少次数的一个;

解决方案 »

  1.   

    select id,count(id) from a group by id
      

  2.   


    select top 1 id,count(id) as [出现次数] from 表a group by id
      

  3.   

    select top 1 * from 
    (select count(id) c,id from A group by id)t
    order by t.c asc
      

  4.   

    select top 1  id,count(id) from table group by id
      

  5.   

    SELECT top 1 * FROM
    (SELECT count(id) c,id FROM A GROUP BY id)t
    ORDER BY  t.c asc
    这个就行了
      

  6.   

    select top 1 id,Count(id) as cnt 
      from table 
     group by id
     order by cnt asc