The catalogue
SQL Interview Questions
36 questions, ordered from easy to hard. Every question runs against a real SQLite database in your browser — no server, no sign-up. Filter by difficulty or topic to focus a session.
36 of 36 questions
- easynot started
Active Users Per Day
Report the number of distinct active users for each date of activity.
GROUP BYAggregationDuplicate handling - easynot started
Article Views I
Find the authors who viewed their own articles at least once.
SELECTWHEREDISTINCT - easynot started
Average Process Time Per Machine
Compute each machine's average time to complete a process.
JOINsAggregationSelf Join - easynot started
Big Countries
Find countries with a large area or population.
SELECTWHERE - easynot started
Classes With At Least 5 Students
Find classes with five or more students enrolled.
GROUP BYHAVING - easynot started
Customers Without Orders
List customers who have never placed an order using an anti-join.
JOINsSubqueriesNULL handling - easynot started
Duplicate Emails
List the email addresses that appear more than once in the person table.
GROUP BYHAVING - easynot started
Employee Bonus
Report every employee's name and bonus, including those with none.
JOINsLEFT JOINNULL handling - easynot started
Employees Earning More Than Their Manager
Find employees whose salary is greater than their direct manager's salary.
JOINsSelf JoinNULL handling - easynot started
Find Customer Referee
Find customers who are not referred by customer id 2.
SELECTWHERENULL handling - easynot started
Invalid Tweets
Find tweets whose content is longer than 15 characters.
SELECTWHEREString Functions - easynot started
Recyclable and Low Fat Products
Find the ids of products that are both low fat and recyclable.
SELECTWHERE - easynot started
Rising Temperature
Find the ids of days when the temperature was higher than the previous day's.
Window FunctionsSelf JoinDate Functions - easynot started
Second Highest Salary
Return the second-highest distinct salary, or NULL when it does not exist.
SubqueriesAggregationNULL handling - easynot started
Subjects Taught By Each Teacher
Count the distinct subjects each teacher teaches.
GROUP BYAggregationDuplicate handling - easynot started
Visits Without Transactions
Count visits with no transactions per customer.
JOINsGROUP BYNULL handling - mediumnot started
Consecutive Login Days
Find users who logged in on three or more consecutive calendar days.
Window FunctionsCTEsDate Functions - mediumnot started
Consecutive Numbers
Find numbers that appear three or more times in a row.
Window FunctionsLAGDuplicate handling - mediumnot started
Customers Who Bought All Products
Find customers who have purchased every product in the catalogue.
SubqueriesGROUP BYHAVING - mediumnot started
Departments by Average Salary
Find departments whose average salary is above the company average.
GROUP BYHAVINGJOINs - mediumnot started
Exchange Seats
Swap the student in each adjacent pair of seats.
CASE WHENSubqueriesOdd/Even - mediumnot started
First and Last Order Per Customer
Show the date of each customer's first and last order.
Window FunctionsAggregationDate Functions - mediumnot started
Game Play Analysis IV
Find the fraction of players who logged in the day after their first login.
Window FunctionsAggregationDate Functions - mediumnot started
Immediate Food Delivery
Report the percentage of customers' first orders that were delivered immediately.
Window FunctionsSubqueriesAggregation - mediumnot started
Latest Event Per User
Return each user's most recent event in full.
Window FunctionsDuplicate handling - mediumnot started
Longest Login Streak
For each user, the length of their longest run of consecutive login days.
Window FunctionsCTEsGaps and Islands - mediumnot started
Monthly Sales Ranking
Rank salespeople by their monthly sales, including ties, and handle months with no sales.
Window FunctionsGROUP BYDate Functions - mediumnot started
Nth Highest Salary
Return the third-highest distinct salary, or NULL when it does not exist.
Window FunctionsSubqueriesNULL handling - mediumnot started
Orders Gap Analysis
Find the gap in days between consecutive orders per customer.
Common Table ExpressionsWindow FunctionsDate Functions - mediumnot started
Percentage of Total Sales
Show each region's share of overall sales as a percentage.
Window FunctionsAggregation - mediumnot started
Pivot Quarterly Sales
Pivot per-year sales rows into one row per year with a column per quarter.
Conditional AggregationCASE WHENGROUP BY - mediumnot started
Rank Scores
Rank tournament scores so ties share a rank with no gaps.
Window FunctionsDuplicate handling - mediumnot started
Running Total
Compute a running total of sales over time, partitioned per account.
Window FunctionsAggregationDate Functions - mediumnot started
Seven-Day Rolling Average
Compute each sale's 7-day rolling average of amount, per account.
Window FunctionsAggregationDate Functions - mediumnot started
Users With the Most Friends
Find the user(s) with the largest number of friends.
UNION ALLGROUP BYAggregation - hardnot started
Top Three Per Category
Return the top three products by revenue per category, including ties.
Window FunctionsJOINsDuplicate handling