SELECT current_date-(DAYOFWEEK (current_date)-2 + (Row_number () over (ORDER in 1))) Day as Resultfrom SYSIBM. Syscolumnsfetch first 7 rows only; output: 2013-03-24 2013-03-23 2013-03-22 2013-03-21 2013-03-20 2013-03-19 2013-03-18 You can see the sentiment The situation, you do a bit of sorting. Cross-examine the minor changes can find out what you said the result is only you this method is to check out all the dates before last week, and then take the first 7, so how to sort it also please advise! Answer Alas, originally I want to lazy ... It seems to be to write their own ah ... SELECT current_date-(DAYOFWEEK (current_date)-1) DAY-7 day+ (Row_number () over (ORDER in 1)) Day as Resultfrom Sysib M.syscolumnsfetch first 7 rows only; query result: 2013-03-18 2013-03-19 2013-03-20 2013-03-21 2013-03-22 2013-03-23 2013-03-24 Note: D Ayofweek is the day of the current week, which is the query. (Sunday is the first day) Current_date-(DAYOFWEEK (current_date)-1) Day is getting the first days of the week (i.e. Sunday March 24) current_date-(DAYOFWEEK (current_date) -1) DAY-7 Day is getting last week's first days (i.e. last week's Sunday March 17) current_date-(DAYOFWEEK (current_date)-1) DAY-7 day+ (row_number () OVE R (ORDER by 1)) Day is starting from last Sunday, each row of data + 1 days. That is, from March 18 is the 1th row, March 19 is the 2nd row fetch first 7 rows only; is only 7 rows are retrieved.
How to get the date of the week before the current date in DB2