这样两条查询语句,得到的记录条数为什么不一样呢?
select distinct name
from studentselect count(name)as name
from 
(
select distinct name
from student
)temp

解决方案 »

  1.   

    你第一个是查找出NAME字段不重复的记录第二个用了COUNT()函数,所以是求出NAME字段不重复记录的条数啊
      

  2.   

    select count(name)as name
    from 
    (
    select distinct name
    from student
    )temp-->聚合函数呢.会忽略NULL的.
      

  3.   

    对,也可能有null值.
    这样试试
    select distinct name
    from student where name is not nullselect count(name)as name
    from 
    (
    select distinct name
    from student where name is not null
    )temp
      

  4.   


    要么是数据变了,要么是有null值
      

  5.   

    你不查COUNT(NAME)使用COUNT(*)试下..因为COUNT(*)不忽略空值.
      

  6.   

    count name 当name is null时是不计算的你试下count(*)
      

  7.   

    哈哈
    完全没理解歪了聚合函数不对NULL进行计算.
      

  8.   

    嘿嘿
    是NULL的问题
    谢谢各位
    俺分少
    大家都这么热情
    不知道给谁好
    一人给一点意思一下吧
    不要嫌少