通過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