db2 sql: how to sum quantities group by next 4 weeks?

Posted on 2011-04-26
Last Modified: 2012-05-11
I have table, with quantity and a date.
How to have the sum of quantity group by the next 4 weeks?
some thing like that:
week 45, quantity 234
week 46, quantity 30
week 47, quantity 34
week 48, quantity 89?
Question by:bobdylan75
    LVL 40

    Assisted Solution

    try this.
    select Week(DateColumn) WeekNumber, sum(Quantity) Total_Quantity
      from your_table
     group by Week(DateColumn)
     order by Week(DateColumn)
     fetch first 4 rows only

    Open in new window

    LVL 37

    Accepted Solution


    select Week(DateColumn) WeekNumber, sum(Quantity) Total_Quantity
      from your_table
     group by Week(DateColumn)
    having week(dateColumn) >= week(current date)
     order by Week(DateColumn)

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
    Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now