帆软报表(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

 

转载于:https://www.cnblogs.com/Williamls/p/11090818.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值