I’m working on a project for school where I need to aggregate data to answer a business question. I’ll change it a bit so I don’t get in trouble with the school, but lets say I have a table that lists the date a car was purchased and the color. I’m trying use that to make a table that has month, color, and total purchased of that color in that month. I think I’m mostly there, but I’m getting the total of all preceding months as well (January is fine, February shows Jan+Feb totals).
Here’s my query:
SELECT EXTRACT(MONTH FROM purchase_date) AS month, color, count(color) AS total FROM sales_table
GROUP BY month, color
ORDER BY month, total DESC
I’m very much a beginner at SQL and would appreciate any advice, or even just a pointer to a good resource/tutorial that could help with this.
Bobby is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.