简体   繁体   English

案例 sql 使用日期 DB2

[英]Case sql using dates DB2

I want to get the month and year of the current date/last month depending on the day.我想根据日期获取当前日期/上个月的月份和年份。

If were on 8th of the month or before, i want to get the last month and year Otherwise ,I want to get the current month and year.如果是在本月的 8 号或之前,我想获得上个月和去年,否则,我想获得当前月份和年份。

How do i do that using sql on DB2?我如何在 DB2 上使用 sql 做到这一点?

Subtract 8 days and use the year() and month() functions:减去 8 天并使用year()month()函数:

select year(current_timestamp - 8 day),
       month(current_timestamp - 8 day)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM