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

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

1 Answer

0 votes
by (86.8k 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.

 

Related questions

0 votes
1 answer
asked Apr 22 in SQL by Sudhir_1997 (36k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in SQL by Tech4ever (20.3k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...