Reputation: 33
I have a table with sample data as below:
I am trying to calculate a current weekly data comparison with previous week value, and to make the output as below:
How can i achieve this:
Upvotes: 0
Views: 372
Reputation: 132
This should work, just change the "#test" to your table name:
SELECT t2.C_Date,
SUM(t2.Prod1 + t2.Prod2 + t2.Prod3) AS Total_sale,
SUM(t1.Prod1 + t1.Prod2 + t1.Prod3) AS Prev_Week_Total_sale
FROM #test t1
INNER JOIN #test t2
ON t1.C_Date = DATEADD(DAY, -7, t2.C_Date)
GROUP BY t2.C_Date
Upvotes: 1