In the sales table I have a column that contains full dates of each sale, I need to split it and add 2 separate columns of month and year to the sales table, and a column that contains the sum of all sales of each month that was.
This is the table I have-
Sales table
| customer_id | date | Quantity |
|---|---|---|
| 123 | 01/01/2020 | 6 |
| 124 | 01/02/2020 | 7 |
| 123 | 01/03/2021 | 5 |
| 123 | 15/01/2020 | 4 |
Here's what I wrote -
ALTER TABLE SALES ADD SELECT DATEPART (year, date) as year FROM SALES;
ALTER TABLE SALES ADD SELECT DATEPART (month, date) as month FROM SALES;
ALTER TABLE SALES ADD SUM_Quantity AS SUM() (Here I was stuck in a query...)
Is this a valid query, and how to write it correctly? Thanks!
