SQL Server Interview Question #81

What are aggregate functions in SQL Server?

Aggregate Functions, GROUP BY & Window Functions Mid-Level Intermediate

Detailed Explanation

Aggregate functions calculate a single result from a set of rows. Common aggregate functions include COUNT, SUM, AVG, MIN, and MAX.

They are frequently combined with GROUP BY to calculate values for each group, such as total sales per customer or product count per category. Most aggregate functions ignore NULL values, while COUNT(*) counts rows regardless of NULL values in individual columns.

Code Example

SELECT COUNT(*) AS ProductCount,
       SUM(Price) AS TotalPrice,
       AVG(Price) AS AveragePrice,
       MIN(Price) AS LowestPrice,
       MAX(Price) AS HighestPrice
FROM dbo.Products;