select bday,bdd,sum(bflag) over(partition by bdd) as dd_sum
from
(select aday,to_char(aday,'day') as dd, 1 as flag
from
(SELECT TO_DATE('20130118', 'YYYY-MM-DD') + LEVEL - 1 DAY
FROM DUAL
CONNECT BY TO_DATE('20130118', 'YYYY-MM-DD') + LEVEL - 1 <=
TO_DATE('20130209', 'YYYY-MM-DD')
) a
) b
group by bday
select tdate, to_char(tdate,'day')
from (
select to_date('2011-03-18','yyyy-mm-dd') + rownum -1 as tdate
from all_objects
where rownum <= to_date('2011-03-30','yyyy-mm-dd') - to_date('2011-03-18','yyyy-mm-dd') + 1
) t
where to_char(tdate,'day') = '星期一'
其中t表是构建你需要的这一个时间段的日期列表, to_char(days,'day')得到的结果是星期几
不要用next_day(sysdate-7,1)-6,试试next_day(sysdate-7,2)
SQL> select next_day(to_date('20120107','yyyymmdd')-7,1)-6 last_monday from dual;
LAST_MONDAY
-----------
2011-12-26
SQL> select next_day(to_date('20120107','yyyymmdd')-7,2) last_monday from dual;
LAST_MONDAY
-----------
2012-1-2
with t as(select date'2015-1-1'+level-1 as dt from dual connect by level<=365)
select dt,to_char(dt,'w') as w,to_char(dt,'day') as d,
trunc((to_char(dt,'dd')+to_char(last_day(add_months(dt,-1)),'d')-1) /7) +1 as e from t;
希望这个能满足你的要求!
select
from (select to_date('2013-01-01', 'yyyy-mm-dd') + rownum - 1 days
from dba_objects) a
where extract(year from days) = 2013
and to_char(days, 'WW') = 22
and to_char(days, 'day') in ('星期一', '星期二', '星期三', '星期四', '星期五')
年份:2013,第几周:22
以上就是关于oracle问题,请教大家,我想要取一个日期区间内的所有周一,二。。。周日,sql怎么下全部的内容,包括:oracle问题,请教大家,我想要取一个日期区间内的所有周一,二。。。周日,sql怎么下、Oracle查询一段日期内的星期的日期..例如我要查2011-3-18至2011-3-30内所有星期一的日期..应该怎样查询、oracle中国年周周一-----周日等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)