表如下 f1
aaa
aaa
bb
bb
cc
aaa
cc统计每个f1的个数,得到如下表
f1   count
aaa   3
bb    2
cc    2

解决方案 »

  1.   


    select f1,COUNT(1) count from table group by f1
      

  2.   

    select f1,COUNT(1) count from table group by f1
      

  3.   


    --直接来
    select f1,count(1) f1cnt from tb group by f1
      

  4.   

    select f1,COUNT(*) count from table group by f1
    楼上均正解
      

  5.   

    加个条件,f1属于table2的,该怎么写
      

  6.   


    select a.f1,COUNT(1) count from table a where exists(select 1 from table2 where a.f1=f1) group by a.f1