如何根据某天:testDay(格式2008-07-08)
计算出:
本周(testDay所在的周)的周一(this_week_beg)和周末(this_week_end),
上周的周一(last_week_beg)和周末(last_week_end ),
上上周的周一(two_week_beg)和周末( two_week_end),
上上上周的周一(three_week_beg)和周末(three_week_end),
本月开始(this_month_beg)和结束( this_month_end),
上月开始(last_month_beg)和结束(last_month_end).
谢谢了....
计算出:
本周(testDay所在的周)的周一(this_week_beg)和周末(this_week_end),
上周的周一(last_week_beg)和周末(last_week_end ),
上上周的周一(two_week_beg)和周末( two_week_end),
上上上周的周一(three_week_beg)和周末(three_week_end),
本月开始(this_month_beg)和结束( this_month_end),
上月开始(last_month_beg)和结束(last_month_end).
谢谢了....
解决方案 »
- Oracle提示the account is locked
- 一个sql语句效率优化
- 纠结的分区和索引方案
- Oracle的Pro*C在预编译时报内存错误,怀疑是源文件大小的问题,帮忙出出主意
- 如何,从DMP全导出文件中恢复数据.
- 10g数据库启动错误提示:Io 异常: The Network Adapter could not establish the connection
- 一条语句
- 高分求数据库冷备份方案,急急急急急急!!!在线等
- 哪位大侠告诉我一声,WINXP能不能装ORACLE
- WIN98下如何配置ODBC?在线等待。。。。!
- Oracle安装的问题
- 请问PLSQL里能使用DECODE语句吗?
decode(to_char(testday,'day'),'1',testday-6,testday-to_number(to_char(testday,'day'))+1) 本周一
case
when to_char(testday,'day')='6'
then to_char(testday,'day')='7' then testday-1
esle testday+6-to_number(to_char(testday,'day'))
end 本周五上周的周一(last_week_beg)和周末(last_week_end ),
算出本周的然后-7
上上周的周一(two_week_beg)和周末( two_week_end),
-14上上上周的周一(three_week_beg)和周末(three_week_end),
-21本月开始(this_month_beg)和结束( this_month_end),
trunc(testday,'mm') 本月开始
last_day(testday) 本月结束
上月开始(last_month_beg)和结束(last_month_end).
add_months(trunc(testday,'mm'),-1)上月开始last_day(add_months(testday,-1)) 上月结束
周日是第一天,周一是第2天,周六是第7天
我们一般的习惯是以周日为最后天的,和数据库有所不同啊
我们这的本周日,在数据库里是下一周的开始(西方的习惯)
==>"decode(to_char(2008-07-08,'day'),'1',2008-07-08-6,2008-07-08-to_number(to_char(testday,'day'))+1)"?
判断
to_char(testday,'day') 的值
如果是1,说明testday是周日,那取周一就是testday减去6天
不是的话,就取testday-to_char(testday,'day') 的值再加2天就是周一
比如8.25是周一
to_char(testday,'day')=2
8.25-2+2=8.25
如果是8.26
就是8.26-3+2=8.25
今天是
8.27
to_char(8.27,'day')=4
8.27-4+2=8.258.24是周日,如果还按这个公式算
8.24-1+2=8.25按我们的习惯8.24不是本周的,算上周的,所以这时就要换个公式
8.24-6=8.18 就是上周一