From the course: SQL Server Fundamentals: Master Basic Query Techniques

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Aggregates

Aggregates - SQL Tutorial

From the course: SQL Server Fundamentals: Master Basic Query Techniques

Start my 1-month free trial

Aggregates

- [Instructor] Doing calculations across multiple rows to find a sum or an average can be a common operation in data analysis and SQL Server provides aggregate functions to do these computations. To do this, we simply have to write a query that indicates how we want to collapse in group rows to do our analysis. For example, in this small sample set, if we want to count the number of rows per item, we could group our query by the item column. We collapse the groups based on unique values in the designated column. So, let's see a few of these aggregate queries in action. So first, if we want to count all of the rows in a table, we would add count star to this query and it would count the number of rows. We didn't provide a grouping condition, so we are basically asking SQL Server to collapse all of the rows in the table to get a count. But if we wanted to count the number of orders per customer, we would group by a column that could uniquely identify an individual customer. So we could…

Contents