Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Grouping data by week
Hi there
Try using TRUNC in your sql. So if you use that with a group by clause then
your sql would look something like the following
SELECT to_char(max(trunc(my_date,'IW')),'DD/MM/YYYY'), sum(data)
from my_table
group by to_char(my_date, 'WI')
kcarlson_at_my-deja.com wrote:
> I'm interested in writing a query that sums and reports data on a
> per-week basis, showing Monday's date for each week. It appears that I
> would need to use "group by to_char(my_date, 'WW')" for the grouping
> part, but how to specify the first day of the week in each output line?
>
> Perhaps I could use something like
> "to_date(to_char(my_date,'WW'),'MM/DD/YY')" but since it covers an
> entire week, which date would be consistently returned?
>
> Thanks for any help,
> Kevin Carlson
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Received on Fri Aug 04 2000 - 00:00:00 CDT