10.4 补充范围内丢失的值

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);

原文地址:https://www.cnblogs.com/l10n/p/7523351.html