0 votes
1 view
in SQL by (30.7k points)

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

1 Answer

0 votes
by (72.4k points)

 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 Course by Intellipaat.


Welcome to Intellipaat Community. Get your technical queries answered by top developers !