mysql 统计时 DISTINCT 的字段有 null值解决办法

coalesce函数表示可以返回参数中的第一个非空表达式,当你有N个参数时选取第一个非空值(从左到右)。

        实例一:

              select coalesce(null,"carrot","apple")

          返回结果:carrot

       实例二:

              select coalesce(1,"carrot","apple")

           返回结果:1

用法:

如果user_id 有为空的情况时可以使用:

SELECT  *,count( DISTINCT COALESCE(user_id,'NULL')) as  visit_count  FROM t

猜你喜欢

转载自tompig.iteye.com/blog/1563930
今日推荐