[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

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

Hi,
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?
thanks
0
bobdylan75
Asked:
bobdylan75
2 Solutions
 
SharathData EngineerCommented:
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

0
 
momi_sabagCommented:
try

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)
0
 
bobdylan75Author Commented:
thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now