Skip to content
Advertisement

Group by range of dates from date_start to date_end columns

I have a table with following table structure:

I want to count how many events (each row is an event) was in every place by each month. If event dates refer to several months, it should be counted for all affected months.

place_id could be repeated, so I did the following query:

So I get following grouped table:

Problem is that data is grouped only by start_date, and its not clear for me how to distribute data by all affected months range from date_start to date_end.

Advertisement

Answer

You can use sequence function to generate the dates between date_start and date_end then explode the generated array column and group by and count as you already did:

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