DataBolt

SQL LEARNING PLATFORM

8

CHAPTER 8

Aggregate Functions

Turning millions of rows into a single meaningful number.

5

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

COUNT — how many rows (with and without NULLs)

2

SUM, AVG — totals and averages

3

MIN, MAX — extremes

4

Combining multiple aggregates

🌟 Think of it this way: Aggregate functions are like a cashier totalling your bill. You bring 20 items (rows) to the counter; they give you back one number (the total). The individual items are collapsed into a single summary.

10.1 - Pagination with OFFSET

SQL QUERY
SELECT COUNT(*) AS total_employees FROM employees;

COUNT (*) vs COUNT(column)

SQL QUERY
SELECT COUNT(*) AS all_rows,
      COUNT(manager_id) AS has_manager
FROM employees;

10.2 - SUM, AVG, MIN, MAX

SQL QUERY
SELECT
    COUNT(*) AS headcount,
    SUM(salary) AS total_payroll,
    AVG(salary) AS avg_salary,
    MIN(salary) AS min_salary,
    MAX(salary) 
FROM employees;

Exercise

Practice your SQL skills

SQL EDITOR
Press semicolon (;) to auto-run query

Tasks

Complete all SQL challenges

1

Find the total number of employees.

Current Task
2

Find the number of employees in IT department.

3

Find the total salary of all employees.

4

Find the total salary of employees in HR department.

5

Find the average salary of all employees.

6

Find the minimum salary among all employees.

7

Find the maximum salary among all employees.

8

Find the average salary of employees in Sales department.

Need help solving this task?