ETL postgresql 加减月份,在postgresql中实现period_diff/month_diff


case when  extract(year from age(b.statdt , a.statdt) ) = 1 and 
        extract(month from age(b.statdt , a.statdt) ) = 0 then 1 else 0 end  Mon12,
case when  extract(year from age(b.statdt , a.statdt) ) = 0 and 
        extract(month from age(b.statdt , a.statdt) ) = 0 then 1 else 0 end  Mon0,
case when extract(month from age(b.statdt , a.statdt) ) = 1 then 1 else 0 end  Mon1,
case when  extract(month from age(b.statdt , a.statdt) ) = 2 then 1 else 0 end  Mon2,
case when  extract(month from age(b.statdt , a.statdt) ) = 3 then 1 else 0 end  Mon3,
case when  extract(month from age(b.statdt , a.statdt) ) = 4 then 1 else 0 end  Mon4,
case when  extract(month from age(b.statdt , a.statdt) ) = 5 then 1 else 0 end  Mon5,
case when  extract(month from age(b.statdt , a.statdt) ) = 6 then 1 else 0 end  Mon6,
case when  extract(month from age(b.statdt , a.statdt) ) = 7 then 1 else 0 end  Mon7,
case when  extract(month from age(b.statdt , a.statdt) ) = 8 then 1 else 0 end  Mon8,
case when  extract(month from age(b.statdt , a.statdt) ) = 9 then 1 else 0 end  Mon9,
case when  extract(month from age(b.statdt , a.statdt) ) = 10 then 1 else 0 end  Mon10,
case when  extract(month from age(b.statdt , a.statdt) ) = 11 then 1 else 0 end  Mon11

你可能感兴趣的:(sql)