Introduction
We use multiple aggregates to get different summary numbers from data in one query. This helps us understand data better in one go.
Jump into concepts and practice - no test required
SELECT AGGREGATE_FUNCTION1(column), AGGREGATE_FUNCTION2(column), ... FROM table_name;
SELECT COUNT(*), SUM(price) FROM sales;
SELECT AVG(age), MAX(age), MIN(age) FROM users;
SELECT COUNT(DISTINCT category), SUM(quantity) FROM products;
CREATE TABLE orders (id INT, amount DECIMAL); INSERT INTO orders VALUES (1, 100.50), (2, 200.00), (3, 50.25); SELECT COUNT(id) AS total_orders, SUM(amount) AS total_amount, AVG(amount) AS average_amount FROM orders;
orders with column amount, what will this query return?SELECT COUNT(*), MAX(amount), MIN(amount) FROM orders;
SELECT SUM(price), AVG(price) FROM sales GROUP BY category;
sales table with columns category and amount. Which query correctly combines these aggregates?