DB2 sql 上期(月、季、年)上月月末,上季末,上年末(统计中常用到) 博客分类: sql DB2 sql 上月月末上季末上年末上期
程序员文章站
2024-03-23 19:38:46
...
SELECT
current timestamp -day(current date) days ,-- 上个月月末 ,能够知道跨年
/*
to_date('2013-02-23','yyyy-mm-dd') -day(current date) days ,-- 上个月月末 ,能够知道跨年
*/
CASE WHEN TO_CHAR('2012-06-22','Q') ='1' THEN to_char(year('2012-12-01')-1)||'-12'
when TO_CHAR('2012-06-22','Q') ='2' THEN to_char(year('2012-06-22'))||'-3'
when TO_CHAR('2012-01-01','Q') ='3' THEN to_char(year('2012-12-01'))||'-6'
when TO_CHAR('2012-01-01','Q') ='4' THEN to_char(year('2012-12-01'))||'-9'
END AS tt , -- 上个季月 能够知道跨年
current date - (month(current date) -1 ) month - day(current date) day --上年年末
from sysibm.sysdummy1;