Skip to content
Advertisement

Return All Months & Years Between Date Range – SQL

I’m a bit stumped how I might go about this.

I have a very basic query, that currently returns sales for each product, by year and month. It is grouping by year/month, and summing up the quantity. This returns one row for each product/year/month combo where there was a sale.

If there was no sale for a month, then there is no data.

I’d like my query to return one row of data for each product for each year/month in my date range, regardless of whether there was actually an order.

If there was no order, then I can return 0 for that product/year/month.

Below is my example query.

Advertisement

Answer

Thank your for your suggestions.

I managed to get this working using another method.

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