作者:Emily___Emily_622 | 来源:互联网 | 2023-09-24 15:08
根据提供的数据求出该日期所在的季度 selectT1.INDEXCODE,T1.CREATETIME,CASEwhenT1.CREATETIME(casewhento_char(S
根据提供的数据求出该日期所在的季度
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')
结果: