结论先行:null值不计数量,空字符串计数量
SELECT
count(id) as id,
count(distinct id) as ids_id,
count(id1) as id1,
count(distinct id1) as ids_id1 ,
count(name) as name1,
count(distinct name) as ids_name1
from
(
SELECT '2' as id
union all
SELECT '3' as id
union all
SELECT '1' as id
)p1
left join
(
SELECT '1' as id1,'' as name
union all
SELECT '2' as id1,'a' as name
)p2
on p1.id = p2.id1
结果如下
结果:null值不计数量,空字符串计数量