如下:
a     b     
---------------------
苹果   0
苹果  美国
苹果  法国
梨     0
梨    英国
梨    德国
香蕉  德国
香蕉  瑞典
香蕉  意大利
想得到的结果:( SQL如何写,谢谢 )
a     count
----------------
香蕉  3

解决方案 »

  1.   

    select a,count(a) from tbl where a="香蕉" group by a
      

  2.   

    select a,count(*)
    from tb
    where a= '香蕉'
    group by a
      

  3.   

    select a,count(b) from tbl
    where a not in
      (
         select a from tbl where b=0
      )
    group by a
      

  4.   

    select a,count(*) as [count] from 表名where a='香蕉'
      

  5.   

    select a,count(*) as count
    from tb
    where a= '香蕉'
    group by a
      

  6.   

    select 
        t.a,
        count(t.*) as [count] 
    from 
        表名 t
    where 
        not exists(select 1 from 表名 where a=t.a and b=0) 
    group by t.a
      

  7.   

    select a,count(b) from tbl
    where a not in
      (
         select a from tbl where b=0
      )
    group by a这个正解