Help - Group data by week?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Help - Group data by week?

  1. #1
    Join Date
    Nov 2001
    Location
    New Brunswick, NJ
    Posts
    67

    Smile

    Help,

    I want to group a weeks worth of data into the first day of the week specified such as the following:

    Week 1________________Week 2
    12/03/01 X____________12/10/01 O
    12/04/01 O____________12/11/01 X
    12/05/01 X____________12/12/01 O
    12/06/01 O____________12/13/01 X
    12/07/01 X____________12/14/01 O
    12/08/01 O____________12/15/01 X
    12/09/01 X____________12/16/01 O
    =========================
    12/03/01 X=4 O=3_____12/10/01 X=3 O=4

    The bottom line is what I'm looking for. How can group a weeks worth of data at a time into sep. buckets?

    Thanks,

    Paul

  2. #2
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    maybe this cud help!!! in the query below, the count of employees who joined during the week will be displayed.

    select trunc(hiredate,'WW'),count(*) from emp
    group by trunc(hiredate,'WW')
    Cheers!
    OraKid.

  3. #3
    Join Date
    Apr 2001
    Location
    hyderabad,india
    Posts
    27

    Group Data

    Hi

    In the group by clause mentioned above you need to add even the year part.

    i.e select to_char(hiredate,'WW'),count(*) from emp
    group by to_char(hiredate,'WW'),to_char(hiredate,'yyyy')

    if you group by only week you might get incorrect results.

    for ex: if you have to dates 12-JAN-1982 & 12-JAN-1983 it would treat both the dates as week no 4 but in reality they both are different. to avoid this you need to add the year part.

    Regards,
    Raghav.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width