sql server 聚合函数对null值的处理

    技术2022-05-19  21

    count(1)和count(*)结果一样,都包括对null的统计,只是执行效率有高低

    count(column)不包括对null值的统计,可以用isnull函数进行转换

    聚合函数avg、max、min、sum 都是忽略null值的,都须通过isnull转换

     

    <>或者!=或者=对null值是不起作用的,如下

    测试数据如下:

    tb:a b c1 2 x

    1 3 null

    1 4  

    1 5 x

    语句select * from tb where c<>'x' 结果为:

    a b c1 4  

     

    须用isnull函数进行转换

     

    select * from tb where isnull(c,'')<>'x'


    最新回复(0)