Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Using aggregations works well when you want just a single row of results for a specific filtered item. If you want to find the average price of several shares, you may be thinking you need to provide a SELECT AVG() for each share. This section will demonstrate that this is not the case. By using GROUP BY, you instruct SQL Server to group the data to return and provide a summary value for each grouping of data. To clarify, as you will see in the upcoming examples, you could remove the WHERE ShareId=1 statement, which would then allow you to group the results by each different ShareId. In Chapter 14, where you will look at more advanced T-SQL, you will see how it is possible to create more than one grouped set. For the moment, though, let’s keep it straightforward.