Hi @Shambhu Rai
You can just use simple GROUP BY with aggregate function(SUM) like this:
SELECT unit,saledate,SUM(data) AS SUM_data
FROM #main5
GROUP BY unit,saledate
Or use window function OVER( PARTITION BY ...)
like this:
SELECT DISTINCT unit,saledate,SUM(data)OVER(PARTITION BY unit,saledate) AS SUM_data
FROM #main5
PARTITION BY does not affect the number of rows returned, but it changes how a window function's result is calculated.And that's why we need to add ‘DISTINCT’in this query.
The OVER clause defines a window or user-specified set of rows within a query result set. A window function then computes a value for each row in the window.
You can use the OVER clause with functions to compute aggregated values such as moving averages, cumulative aggregates, running totals, or a top N per group results.
In this issue,I tend to recommend using 'GROUP BY'
Best regards,
LiHong