我正在尝试标记所选滚动日期和之前4个月标准的数据。 如果说
,我该如何写一个案例Case when X=1 and Y=2 And between Date- 4months Then '1'
When X =2 and Date(Year/month)- 4monthsDate Then '2'
END ) AS Flag
GROUP BY MONTHOFDATE
答案 0 :(得分:1)
最好使用ADD_MONTHS函数:
CASE
WHEN X = 1 AND
Y = 2 AND
SOME_DATE BETWEEN ADD_MONTHS(SYSDATE, -4) AND SYSDATE
THEN '1'
WHEN X = 2 AND
SOME_DATE BETWEEN ADD_MONTHS(SYSDATE, -4) AND SYSDATE
THEN '2'
END AS FLAG
祝你好运。