如果a.col的值是Null的话,count()不会计数。

解决方案 »

  1.   

    但是mysql里面确实是计数了:
    col0    col1       
    ------------------
    1                  
    2       test1      
    3       test2      
    4                  
    ------------------
    select count(distinct a.col1)
    from a得到的结果是3啊!很郁闷~~~
      

  2.   

    col1的值是'',不是null如果是'',虽然显示为空,但一定会计数;而是null则不会计数。你可以这样写:
    SELECT Sum(If(col1='' or col1 IS NULL,0,1)) 总数 FROM (SELECT DISTINCT col1 from 表a) b;
      

  3.   

    觉得是数据表定义有问题!如果是NULL 你可以这样写:select count(distinct col1) from a where col1 is not null; 否则 select count(distinct col1) from a where SELECT count(*) from test where if(t1='',0,1);
    ps:mathematician,你的那种子选择嵌套在mysql 能用吗?4.1以后mysql 才有限支持子选择语句的
      

  4.   

    fanyi2003(才鸟):
    mysql4.1以后支持子查询,建议你升级mysql