Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2012

    Unanswered: Group By 3 months Query - Urgent

    Hi Guyz,

    I want to group the data for the last 3months from the given date
    For below data, i want to take last 3 months avg

    A 1-Jan-09 10
    A 1-Feb-09 20
    A 1-Mar-09 30
    B 1-Jan-09 10
    B 1-Feb-09 20
    B 1-Mar-09 30

    i need the following output

    A 1-Jan-09 10
    A 1-Feb-09 15
    A 1-MAR-09 20
    B 1-Jan-09 10
    B 1-Feb-09 15
    B 1-MAR-09 20

    Need a query for this?

    Thanks in advance
    Subbiah K

  2. #2
    Join Date
    Oct 2002
    Cape Town, South Africa
    You have not provided a table structure so I can not provide you with the 100% answer, but here is pseudo code:
    select to_char(date_col, 'Q') quarter_num, trunc(date_col, 'Q') quarter_date, sum(value) total
    from table_list
    group by to_char(date_col, 'Q'), trunc(date_col, 'Q')
    You need to review the Oracle documentation for the date formats that can give you the different parts of a date.

Posting Permissions

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