chenjialin2000 发表于 2013-1-13 18:27:04

db2 日期维度SQL

select rq,       dayofweek_iso(rq) as "星期中第几天",       case dayofweek_iso(rq)         when 7 then          '星期天'         when 1 then          '星期一'         when 2 then          '星期二'         when 3 then          '星期三'         when 4 then          '星期四'         when 5 then          '星期五'         when 6 then          '星期六'       end as 星期,       day(rq) as "月中第几天",       ceiling(day(rq)*1.0/7) as "月中第几周",       month(rq) as "月份",       days(date(rq)) -days(date('0001-01-01') + (year(rq) - 1)years + ((ceiling(month(rq) * 1.0 / 3)) * 3 - 3) months) + 1 as "季中第几天",       case mod(month(rq), 3)         when 0 then          3         else          mod(month(rq), 3)       end as "季中第几月",       (ceiling(month(rq) * 1.0 / 3)) as "季度",       dayofyear(rq) as "年中第几天",       week_iso(rq) as "年中第几周",       (ceiling(month(rq) * 1.0 / 3)) as "年中第几季",       year(rq) as "年",       case dayofweek_iso(rq)         when 7 then          1         when 6 then          1         else          0       end as "周末标志"from sj
页: [1]
查看完整版本: db2 日期维度SQL