Rohit
Rohit

Reputation: 1550

how to summarize sql result, week and month wise in single query

I want to summarize sql query result week wise and month wise at the same time in a grid view. Is this even possible or I am just dreaming?

Requirement:

  1. Show last one month data and next two month's data week wise in the grid.

    Example-

    • If the current month is September then I want to show data from 1st August to 31st October categorized in weeks.
  2. Show the data after the next month of current month in month wise view in the same grid.

    Example-

    • data for month November and December will be shown categorized in month not in weeks.

grid or result should look something like below -

enter image description here

Please suggest something to achieve this

Upvotes: 0

Views: 393

Answers (2)

Denis Kohl
Denis Kohl

Reputation: 750

I think you must work with group by or group by ... cube

SELECT x , y from <tabel> GROUP BY  date_feld( to_char( 'MM' ))

but i don't now your DBMS so i can't give you a exact example for the date handling.

Upvotes: 1

Bulat
Bulat

Reputation: 6979

If you want a maintainable solution, use two independent queries, one for weekly aggregation other for monthly. Depending on the input run corresponding query.

Upvotes: 1

Related Questions