• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

SQL Query - Grouping by weekly date range

I need help with a SQL query to group it by weekly date.  Not sure how to go about doing this so that I can get the date to group from Monday - Sunday and give me the sum.  Below is my query and example:

SELECT NAME, DATE, REG, OVT, TOTAL
FROM TIME

It's a simple query, but I need to be able to group it.  See the screenshot example. Example raw data and final result.
0
holemania
Asked:
holemania
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can "GROUP BY" the expressions:

GROUP BY DATEPART(year, your_date_field) , DATEPART(week, your_date_field)

hope this helps
0
 
holemaniaAuthor Commented:
Thank you.  That worked.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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