Extract data using sql query

I have a table named orders which has orderdate and sales column. I want to see sales at monthly level and see how they contributed to the yearly sales. The output should be month, year and sales contribution

You need to use the function Year() and Month() the transform the orderdate. You need the function SUM() to get the total sales at monthly level. Once you have that you need the total amount of yearly sales. That is the most tricky part. You can use the SUM() OVER function for that.

This query will help you a lot, you can use this to get to the final result.

YEAR(Orderdate) AS Year,
MONTH(OrderDate) AS Month,
SUM(sales) AS TotalSalesByMonth,
SUM(sales) OVER (PARTITION BY YEAR(orderdate)) AS TotalSalesByYear
FROM orders