count()为空时取值为0

通过count(行数)可以取到0

with
ect1 as
  (select id from user where is_blacklist=0),
ect2 as
  (select s1.id,s1.type,s1.date
  from email s1 where s1.send_id in ect1
  and s1.receive_id in ect1
  ),
ect3 as
  (select a.date,count(a.id) as num1,

    <!----以下通过取行数获得cout()为0------>
    (select count(1) from ect2 b
      where type='no_completed' and a.date=b.date) as num2
  from ect2 a
  group by date)
select date,cast(num2 as FLOAT)/cast(num1 as flaot) from ect3

posted @ 2022-03-04 16:05  Octoberzbear  阅读(926)  评论(0)    收藏  举报