Skip to content
Advertisement

I need an SQL query to sum all items in an SQL between a specific data range

I need an sql query that will sum the sales of all products sold, by product, within a specific date range. Column “Product” Contains all product items. Column Date contains the date the item was sold and column value contains the actual sales value. So the result should contain just 2 columns, one for the product Name and one for the value, and several rows, which will show the sales total of each product item.

Advertisement

Answer

Are you just looking for GROUP BY with filtering?

select product, sum(sales)
from t
where date >= @date1 and date <= @date2
group by product;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement