In this step by step SQL Tutorial I will show you how to using SQL Group by Year from date field and use aggregate function. For the purpose of this tutorial I will use SQL Server 2012.
Prior knowledge: It might be easier for you to follow this tutorial if you have knowledge of Aggregate functions and Group by for more information visit SQL Group By.
We are going to show you how to use Year and Sum aggregate function with Group by this knowledge might help with questions like
how to get Total sales amount for each year. In the following example I will show you how you could write the query.
Below I use Year function with ShipDate field and display new column as SalesYear in SELECT then I use group by with Year on ShipDate field.
As you can see we "aggregated" date to Year level using Year function and placed it both in Group by clause and select clause.
Once I have Sales Year I added Sum aggregate function to select with SalesAmount field to get Total Sales Amount.
Hope that helps