Skip to content
COURSE TOPIC

SQL for Data Analysis: Filters, Joins and Window Functions

Filter, combine, group, and rank database records with SQL to answer practical business questions.

Part of course Data Analyst Course
Difficulty Level
Beginner to intermediate
Estimated Learning Time
3-4 hours
OVERVIEW

About SQL for Data Analysis: Filters, Joins and Window Functions

SQL retrieves and analyzes information in relational databases. Analysts select columns, filter rows, combine related tables, and calculate summaries in repeatable queries.

LEARNING OUTCOMES

What You Will Learn

  • Filter data using SELECT, WHERE, and ORDER BY.
  • Summarize with aggregates, GROUP BY, and HAVING.
  • Join tables while checking keys and row counts.
  • Use CTEs and window functions for multi-step analysis.
TOPIC GUIDE

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.

PRACTICAL EXAMPLE

Example / Code

Example
WITH order_revenue AS (
 SELECT DATE_FORMAT(order_date, '%Y-%m') AS month, category, quantity * unit_price AS revenue FROM sales
)
SELECT month, category, SUM(revenue) AS total_revenue,
 RANK() OVER (PARTITION BY month ORDER BY SUM(revenue) DESC) AS category_rank
FROM order_revenue GROUP BY month, category;
TRY IT YOURSELF

Practice Task

Apply what you learned with a practical activity.

Query orders and customers to report monthly revenue by region. Include a date filter, join check, grouped totals, and ranking. Explain how unmatched customer records affect results.

TOOLKIT

Tools & Technologies

  • SQL
  • Relational databases
  • JOINs
  • GROUP BY
  • CTEs
  • Window functions
READY FOR THE COMPLETE COURSE?

Go Beyond SQL for Data Analysis: Filters, Joins and Window Functions

Explore the complete Data Analyst Course curriculum, practical training, learning path and course details.