Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone explain how to get month wise data in SQL?

1 Answer

0 votes
by (119k points)
edited by

Suppose, you want to calculate the total sales of products each month. You can use the following query to get the month-wise data:

SELECT SUM (product_sales), MONTH (Sales_date)

FROM Sales

GROUP BY MONTH (Sales_date), YEAR (Sales_date);

In the above query, we used MONTH() and YEAR() functions to extract the month and year from the date, used group by a month, and sum function to calculate the total sales for each month.

Note: Make sure the Sales_date is in DateTime format, otherwise use the CONVERT() function to change to DateTime format.

If you want to take a course that can provide Instructor-led training and certification then take up this SQL training Online by Intellipaat.

Related questions

0 votes
1 answer
asked Apr 22, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked May 7, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer

Browse Categories

...