时间:2019-05-06 13:52:34
select * from errorinfo; select count(1) from errorinfo; select distinct info from errorinfo; select count(distinct info) from errorinfo;

distinct 会将所有NULL合并为一项
count(distinct)会将NULL除去。
select count(distinct info), info from errorinfo group by info

null不参与count运算,同样适用于sum, avg。
distinct时,所有null作为一个值。
还可以这么用
SELECT *,count( DISTINCT COALESCE(user_id,'NULL')) as visit_count FROM t
本文介绍了SQL查询中`distinct`关键字在处理NULL值时的行为,以及如何使用`count(distinct)`和`COALESCE`函数,重点讨论了在errorinfo表中的应用实例。
1292

被折叠的 条评论
为什么被折叠?



