sum(case when t.ride_num=1 then 1 else 0 end ) as ride_1_times

count(case when t.ride_num=1 then 1 else null end ) as ride_1_times 

count(case when t.ride_num=1 then 1  end ) as ride_1_times 

then=1,两者查询的结果是一样的,但是sum 中case when的else 需要为0,而count case when的 else 只能为null或者不写(因为count默认不统计null值),不能为0

 count case when 与sum case when 的 区别

相关文章: