Preface: Generally do data statistics write stored procedures when I believe many friends have to deal with the date, this is my data processing, do statistics. At that time the request must show a date. Especially when the statistics of the week, especially disgusting, so I used to date the operation of the stored procedures in the SQL, to share with you. Hope to be able to be helpful to everybody. Not much nonsense, directly on the SQL.
Select A.* from (
Select To_char (datetime, ' yyyy-mm ') as month, datetime as start date, datetime+6 as end date,
To_char (dateTime, ' W ')
As the first weeks from
(
Select Datetime,rownum rn from
(
With T as
(select Rownum-1 rn from dual connect by rownum<=10000)
Select To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn as dateTime from T where To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn<= Sysdate
b where To_char (B.datetime, ' day ') = ' Monday '
)
) A
You can directly query for the date of Monday and Sunday of each month, and then belong to the first few weeks
With T as
(select Rownum-1 rn from dual connect by rownum<=10000)
is to assign to t the data queried (select Rownum-1 rn from dual connect by rownum<=10000) for easy use
With T as
(select Rownum-1 rn from dual connect by rownum<=10000)
Select To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn as dateTime from T where To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn<= Sysdate
Get a date from February 1, 2015 to February 1, 2015 plus 10,001 days
Select Datetime,rownum rn from
(
With T as
(select Rownum-1 rn from dual connect by rownum<=10000)
Select To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn as dateTime from T where To_date (' 2015-02-01 ', ' yyyy-mm-dd ') +rn<= Sysdate
b where To_char (B.datetime, ' day ') = ' Monday '
This SQL can be obtained from February 1, 2015 to February 1, 2015 plus 10,001 days between Monday dates
To run the effect of the display:
I would like to do weekly and daily work on the write stored procedures a little help.