简体   繁体   中英

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.

How do i do that using sql on DB2?

Subtract 8 days and use the year() and month() functions:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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