1. 程式人生 > >10.4 補充範圍內丟失的值

10.4 補充範圍內丟失的值

trac emp sce coalesce min count int -1 left join

select y.yr.coalesce(x.cnt,0) as cnt
from (
select min_year-mod(cast(min_year as int),10)+rn as yr
from (
select (select min(extract(year from hreadate))
from emp) as min_year,
id-1 as rn
from t10
) a
) y
left join
(
select extract(year from hredate) as yr,count(*) as cnt
from emp
group by extract(year from hiredate)
) x
on (y.yr=x.yr);

10.4 補充範圍內丟失的值