Learn SQL for Data Analysis: Filters, Joins and Window Functions
Filter and summarize
SELECT chooses fields, WHERE filters records, and ORDER BY makes results easier to inspect. SUM, COUNT, and AVG calculate summaries. GROUP BY defines groups, while HAVING filters aggregated results.
Join related tables safely
A join connects tables such as orders and customers using a key. Confirm key uniqueness and choose a join intentionally: an inner join keeps matches, while a left join retains every first-table row. Compare row counts before and after joining to detect accidental duplication.
Use CTEs and window functions
A Common Table Expression names an intermediate query step and separates preparation from final aggregation. Window functions calculate across related rows without collapsing them: rank categories, compare periods, or calculate running totals.
Validate results
Inspect sample records, compare totals with a baseline, and consider NULL values. Select only needed fields and filter appropriately.
Practice
Join orders to customers by customer_id, calculate revenue from quantity and unit price, and summarize by month and region. Rank regions within each month. Check that rows were not multiplied and decide how to report unmatched orders.