帆軟報表(finereport)根據提供的數據求出該日期所在的季度


根據當前日期求字段中日期的季度 

Oracle數據庫

select
T1.INDEXCODE
,T1.CREATETIME 
,CASE when T1.CREATETIME = 
(case when to_char(SYSDATE,'MM')/3-1 <= 0 
then TRIM(to_char(SYSDATE,'YYYY')-1)||'-'||TRIM(4+(to_char(SYSDATE,'MM')/3-1))
else TRIM(to_char(SYSDATE,'YYYY'))||'-'||TRIM(to_char(SYSDATE,'MM')/3-1)
end) then '本季度' 
when T1.CREATETIME = 
(case when to_char(SYSDATE,'MM')/3-2 <= 0 
then TRIM(to_char(SYSDATE,'YYYY')-1)||'-'||TRIM(4+(to_char(SYSDATE,'MM')/3-2))
else TRIM(to_char(SYSDATE,'YYYY'))||'-'||TRIM(to_char(SYSDATE,'MM')/3-2)
end)
then '前1季度' 
when T1.CREATETIME = 
(case when to_char(SYSDATE,'MM')/3-3 <= 0 
then TRIM(to_char(SYSDATE,'YYYY')-1)||'-'||TRIM(4+(to_char(SYSDATE,'MM')/3-3))
else TRIM(to_char(SYSDATE,'YYYY'))||'-'||TRIM(to_char(SYSDATE,'MM')/3-3)
end) 
then '前2季度' 
when T1.CREATETIME = 
(case when to_char(SYSDATE,'MM')/3-4 <= 0 
then TRIM(to_char(SYSDATE,'YYYY')-1)||'-'||TRIM(4+(to_char(SYSDATE,'MM')/3-4))
else TRIM(to_char(SYSDATE,'YYYY'))||'-'||TRIM(to_char(SYSDATE,'MM')/3-4)
end) 
then '前3季度' 
when T1.CREATETIME = 
(case when to_char(SYSDATE,'MM')/3-5 <= 0 
then TRIM(to_char(SYSDATE,'YYYY')-1)||'-'||TRIM(4+(to_char(SYSDATE,'MM')/3-5))
else TRIM(to_char(SYSDATE,'YYYY'))||'-'||TRIM(to_char(SYSDATE,'MM')/3-5)
end)
then '前4季度' END as 指標
from TableA  t1
INNER JOIN TableB  t2 on T1.indexcode = t2.indexcode 
where T2.indexcode in ('I1301000019')

結果:

在報表中使用動態參數,根據所選擇日期信息展示所在季度各指標

select  

CREATETIME 
,CASE when T1.CREATETIME = '${jd}' then '本期' 
when T1.CREATETIME = 
(case when SUBSTR('${jd}',-1,1)-1<=0 
then SUBSTR('${jd}',1,4)-1||'-'||(4+SUBSTR('${jd}',-1,1)-1)
else SUBSTR('${jd}',1,4)||'-'||(SUBSTR('${jd}',-1,1)-1)
end)
then '前1期' 
when T1.CREATETIME = 
(case when SUBSTR('${jd}',-1,1)-2<=0 
then SUBSTR('${jd}',1,4)-1||'-'||(4+SUBSTR('${jd}',-1,1)-2)
else SUBSTR('${jd}',1,4)||'-'||(SUBSTR('${jd}',-1,1)-2)
end) 
then '前2期' 
when T1.CREATETIME = 
(case when SUBSTR('${jd}',-1,1)-3<=0 
then SUBSTR('${jd}',1,4)-1||'-'||(4+SUBSTR('${jd}',-1,1)-3)
else SUBSTR('${jd}',1,4)||'-'||(SUBSTR('${jd}',-1,1)-3)
end) 
then '前3期' 
when T1.CREATETIME = 
(case when SUBSTR('${jd}',-1,1)-4<=0 
then SUBSTR('${jd}',1,4)-1||'-'||(4+SUBSTR('${jd}',-1,1)-4)
else SUBSTR('${jd}',1,4)||'-'||(SUBSTR('${jd}',-1,1)-4)
end)
then '前4期' END as 季度

from  table

 

 

規范日期:將字符串形式的'2019-08-01'變成‘8/1’類型

select replace(str(substring('2019-08-01',6,2)*1)+'/'+str(right('2019-08-01',2)*1),' ','')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM