Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: SQL Question
> -----Original Message-----
> From: Viktor [mailto:stant_98_at_yahoo.com]
>
> I want to select some data given a certain date
> range,i.e where some_date between start_date and
> end_date.
> Is there a way to group the output by week?
I saw several suggestions to use the "to_char" function. I personally prefer to use the trunc function in the group by, because in a test once I found that the trunc function was a little faster. Of course I'm no performance guru so I might be incorrect. You can use the trunc function with the following "formats" for weeks:
WW Same day of the week as the first day of the year.
IW Same day of the week as the first day of the ISO year.
W Same day of the week as the first day of the month.
e.g.
SQL> select to_char (trunc (last_ddl_time, 'IW'), 'YYYY/IW'),
2 count (*) 3 from dba_objects 4 group by trunc (last_ddl_time, 'IW') ;
TO_CHAR COUNT(*)
------- ----------
2001/01 21783 2001/04 21 2001/05 2 2001/07 671 2001/08 7 2001/09 17 2001/10 511 2001/12 1 2001/13 5 2001/14 1 1
![]() |
![]() |