By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
The only real problem here is which date function you can use. Date functions actually precede the adoption of SQL Standards for temporal datatypes, so many database systems have their own, proprietary functions. In Standard SQL, the function you need here is EXTRACT.
SELECT EXTRACT(MONTH FROM salesdate) AS salesmonth , salesperson , SUM(salesqty) AS total_sales FROM widget_sales GROUP BY EXTRACT(MONTH FROM salesdate) , salesperson ORDER BY EXTRACT(MONTH FROM salesdate) , total_sales DESC
This query will combine monthly sales for all years, if the table contains data for more than one year (although your question seems to suggest that it doesn't).
Notice that the ORDER BY clause sorts the results into months, and then within each month, by decreasing total sales.
Dig Deeper on Oracle and SQL
Related Q&A from Rudy Limeback
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clausecontinue reading
Read an example of an SQL case expression from our SQL expert Rudy Limeback.continue reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.