年度開始日期 : trunc(sysdate,'Y')
第一季的結束日期 : add_months(trunc(sysdate,'Y'),3 )-1
...
第四季的結束日期 : add_months(trunc(sysdate,'Y'),12)-1
select UNIT,
sum(case when txdate< trunc(sysdate,'Y') then AMT else 0 end) BeginAMT,
sum(case when txdate<=(add_months(trunc(sysdate,'Y'),3 )-1) then AMT else 0 end) Q1,
sum(case when txdate<=(add_months(trunc(sysdate,'Y'),6 )-1) then AMT else 0 end) Q2,
sum(case when txdate<=(add_months(trunc(sysdate,'Y'),9 )-1) then AMT else 0 end) Q3,
sum(case when txdate<=(add_months(trunc(sysdate,'Y'),12)-1) then AMT else 0 end) Q4
from TABLENAME
where txdate <= sysdate
group by UNIT;
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。