我有一张表和
列Start_date timestamp,
end_date timestamp,
id number,
cost number(10,2).
我插入表格的数据将会是这样的
1,'2013-02-03 00:00:00','2013-02-03 00:00:00',75*0.06
1,'2013-02-04 00:00:00','2013-02-04 00:00:00',75*0.06
1,'2013-02-05 00:00:00','2013-02-05 00:00:00',75*0.06
1,'2013-02-06 00:00:00','2013-02-06 00:00:00',75*0.06
1,'2013-02-07 00:00:00','2013-02-07 00:00:00',75*0.06
1,'2013-02-08 00:00:00','2013-02-08 00:00:00',75*0.06
1,'2013-02-09 00:00:00','2013-02-09 00:00:00',75*0.06
现在我希望在星期日到星期六之前将列Start_date
和end_date
分组。
先谢谢。
答案 0 :(得分:0)
这是我能为您提供的最佳服务,因为您无法理解您的问题以及您提供的样本。 2013年ISO周表:
SELECT start_date -- 1/1/2013 --
, TRUNC(start_date, 'iw') wk_starts
, TRUNC(start_date, 'iw') + 7 - 1/86400 wk_ends
, TO_NUMBER (TO_CHAR (start_date, 'IW')) ISO_wk#_iw
, TO_CHAR(start_date, 'DAY') wk_day
FROM
(
SELECT TRUNC(SYSDATE, 'YEAR')-1 + LEVEL AS start_date
FROM dual
CONNECT BY LEVEL <=
(
SELECT TRUNC(ADD_MONTHS (SYSDATE, 12), 'Y')-TRUNC(SYSDATE, 'Y') "Num of Days in 2013"
FROM dual
)
)
/
START_DATE WK_STARTS WK_ENDS ISO_WK# WK_DAY
----------------------------------------------------------------------
1/1/2013 12/31/2012 1/6/2013 11:59:59 PM 1 TUESDAY
1/2/2013 12/31/2012 1/6/2013 11:59:59 PM 1 WEDNESDAY
.....
1/7/2013 1/7/2013 1/13/2013 11:59:59 PM 2 MONDAY
1/8/2013 1/7/2013 1/13/2013 11:59:59 PM 2 TUESDAY
.....
您可以根据它添加任何其他格式的日期和订单......