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)
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.