Skip to content
Advertisement

Split date range into weeks in sql

Given a table called Project, I need the list of team_id’s who won at least an award every week in last 3 months

last 3 months can be achieved with below where condition but how do i split the launch_date into weekly intervals

With the given data, answer should be team id 123

Advertisement

Answer

In your sample data, You have only given 21 days of data instead of 3 months.

You can find out the total number of weeks and their week starting date which can then be compared with your table data to check if an award is won by the team for each week as follows:

In WKS cte for 3 months data, You need to replace the

with

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement