Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: SQL Question

RE: SQL Question

From: Jacques Kilchoer <Jacques.Kilchoer_at_quest.com>
Date: Tue, 03 Apr 2001 12:07:32 -0700
Message-ID: <F001.002E0315.20010403121036@fatcity.com>

> -----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




Jacques R. Kilchoer
(949) 754-8816
Quest Software, Inc.
8001 Irvine Center Drive
Irvine, California 92618
U.S.A.
http://www.quest.com Received on Tue Apr 03 2001 - 14:07:32 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US