T-SQL 101: 87 Summarise sections of data by using GROUP BY
When you calculate an aggregate, the default is that it applies to the entire table, but you might not want that.
For example, I might want to calculate the longest shelf life for products. But I want to calculate that for each size of product.
If we look at the first example, we have added a GROUP BY clause to our query, and it returns exactly that. The output is on the left hand side below the query. For each size (determined by the GROUP BY), the maximum of the shelf life is returned.
2021-03-01