Guided Notes

Counting & Summarizing with GROUP BY

COUNT, SUM, AVG, MIN, MAX, COUNT(DISTINCT), GROUP BY and HAVING — answering 'how many and how much by group' questions on encounters.

Aggregate functions

Slide 1 / 5

• COUNT(*) — number of rows. • COUNT(DISTINCT patient_id) — number of unique patients. • SUM(total_charges), AVG(...), MIN(...), MAX(...). • Aggregates ignore NULLs (except COUNT(*)).

SELECT COUNT(*) AS encounters, COUNT(DISTINCT patient_id) AS patients FROM encounters;

← Your First SQL Queries