-2

我有一张桌子和像这样的列

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

你能帮我解决这个问题吗?

提前致谢。

4

1 回答 1

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
.....

我猜您可以为您的日期和订单添加任何其他格式...

于 2013-02-12T17:32:29.517 回答