I am using PostgreSQL 8.3. I have a table like this:
id regist_time result
-----------------------------------
1 2012-07-09 15:00:08 3
2 2012-07-25 22:24:22 7
4 2012-07-07 22:24:22 8
regist_time
's data type is timestamp
.
I need to find a week time interval(start to end) and sum(result) as num.
I want to get the result as:
week num
---------------------------------
7/1/2012-7/7/2012 10
7/8/2012-7/14/2012 5
7/15/2012-7/21/2012 3
7/22/2012-7/28/2012 11
I can get the week number just in this year:
SELECT id,regis_time, EXTRACT(WEEK FROM regis_time) AS regweek
FROM tba
The key part is
EXTRACT(WEEK FROM regis_time)
extract function can only get the week number in this year, how can I get start time to end time in one week?