Preface: Generally do data statistics write stored procedures when I believe that many friends have to deal with the date, which I was at that time to deal with the data, do statistical use. The date must be displayed when making the request. Especially on the week statistics, especially disgusting, so I used to date operation of the SQL in the stored procedure, to share with you. Hope to be able to help you. 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 few 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
Can be queried directly for the dates of Monday and Sunday of each month, and then the week
With T as
(select Rownum-1 rn from dual connect by rownum<=10000)
is to assign the data queried (select Rownum-1 rn from dual connect by rownum<=10000) to T 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 dates 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 dated from February 1, 2015 to February 1, 2015 plus 10,001 days between Monday
To run the displayed effect:
I want to write a stored procedure to do weekly and daily newspaper a little help.