SQL Query Challenges
Explore how to write complex SQL queries within Python using pandas and sqlite3 to solve real-world interview problems. Learn to implement aggregation with CTEs, joins, window functions, and filtering to identify key insights in employee and e-commerce data.
We'll cover the following...
SQL is one of the most commonly evaluated skills in data interviews. Whether you're analyzing customer behavior or optimizing internal dashboards, you’ll need to write clear, performant queries. In this lesson, we’ll practice using SQL within Python to answer complex real-world prompts. Let’s get started.
Writing a SQL Query
You’re given an Employees table with the following schema:
(id INTEGER, name TEXT, salary INTEGER, department_id INTEGER)
Your task is to write a SQL query that returns employees whose salary is greater than the average salary of their department.
Let’s assume the interviewer has defined a sample function taking care of basic table creation and data insertion for you. You need to fill out the find_high_earners function (line 38), implementing your SQL query with ...