I am trying to summarize total per multiple period range and display them in new columns. I have done simple sum function in sql but only based on one date range. Now I would like to show sums of totals per various date ranges.
To be honest, I don't even know how to solve this issue. I know how to show sum of totals only per one period in one column. Any direction on this would be greatly appreciated.
Thank you!
CREATE TABLE PriceTest ( Product VARCHAR(250), Price NUMERIC(10,2), Pricedate DATETIME )
INSERT INTO PriceTest (product, price, pricedate) VALUES ('A',
10.00,'2019/12/31'),
('B', 50.00,'2019/12/31'),
('C', 30.00,'2019/12/31'),
('D', 50.00,'2019/12/31'),
('A', 20.00,'2019/10/31'),
('B', 40.00,'2019/10/31'),
('C', 50.00,'2019/10/31'),
('D', 10.00,'2019/11/30');
SELECT product, SUM (price) AS '2019-12-31' FROM
pricetest WHERE pricedate='2019-12-31' GROUP BY product,
pricedate
Actual result:
product 12/31/2019
A 10
B 50
C 30
D 50