Select Count(distinct 字段) from table where 字段=值

解决方案 »

  1.   

    select name,count(name) as 出現次數 form table group by name;
      

  2.   

    具体一点说:我的表里有10个字段,每个字段是整型可存任意一个1到100的数字,现在已有纪录若干条!!!
    我现在下想统计一下99这个数字在我的表里出现了多少次???如何写sql语句???
      

  3.   

    有个笨方法,select count(字段1),count(字段2),...,count(字段10) from table1 where 
    字段1=99 or 字段2=99 or ... or 字段10=99
      

  4.   

    select count(*) from table1 where 
    字段1=99 or 字段2=99 or ... or 字段10=99 
      

  5.   

    select sum(case when field1 = 99 then 1 else 0 end)+ 
           sum(case when field2 = 99 then 1 else 0 end)+
           ......
           sum(case when field10 = 99 then 1 else 0 end)
    from table
    这样做的缺点是代码量比较大,好处是结构简单,方便通过代码自动生成.而且效率并不低.
      

  6.   

    Focus的方法应该可以解决你的问题!
      

  7.   

    如果一个数字在一条记录里出现多次,Focus的方法还管用吗???