Advanced SQL Interview Questions — 79 Challenges (6 Free)

These are the 79 Hard challenges in the bank: the questions a senior analyst or data scientist screen ends on. Most of them combine two or three ideas in one query, so the sections below overlap on purpose. The 6 free previews are listed first inside each section.

Find your weakest skill first →

Hard window function questions: 47 challenges (6 free)

Ranking inside partitions, running totals with explicit frames, gaps and islands, period-over-period change with LAG. The hard part is rarely the function. It is choosing the partition and the order that make the numbers mean what the question asked.

Counted from the challenge bank, September 2026. Easy first, then Medium, then Hard.

Hard Free preview

Cumulative Distinct Customers Over Time

Uses: SELECT CTE Window Functions

Try it →
Hard Free preview

Salary Rank Within Department

Uses: SELECT Window Functions ORDER BY

Try it →
Hard Free preview

Running Total Revenue

Uses: SELECT Subquery Window Functions

Try it →
Hard Free preview

Year-over-Year Growth

Uses: SELECT Subquery Window Functions

Try it →
Hard Free preview

7-Day Rolling Revenue Average

Uses: SELECT Window Functions CTE

Try it →
Hard Free preview

Multi-CTE Revenue Pipeline

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Salary Percentile Ranking

Uses: SELECT Window Functions PERCENT_RANK

Try it →
Hard Pro

Order Sessionization by Customer

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

First and Last Order per Customer

Uses: SELECT Window Functions FIRST_VALUE

Try it →
Hard Pro

Cumulative Revenue Share (Pareto)

Uses: SELECT Window Functions SUM

Try it →
Hard Pro

Moving Average with Dynamic Window

Uses: SELECT Window Functions Frame Clause

Try it →
Hard Pro

Nth Highest Salary per Department

Uses: SELECT Subquery Window Functions

Try it →
Hard Pro

Rank Movies by Rating

Uses: SELECT Window Functions ORDER BY

Try it →
Hard Pro

Salary Lead-Lag Gap Within Department

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Top Earner Per Department

Uses: SELECT Window Functions Subquery

Try it →
Hard Pro

3-Movie Rolling Average Revenue

Uses: SELECT Window Functions Frame Clause

Try it →
Hard Pro

Fare Percentile Ranking

Uses: SELECT Window Functions NTILE

Try it →
Hard Pro

Revenue Share by Category (Window %)

Uses: SELECT Window Functions SUM

Try it →
Hard Pro

RANK vs DENSE_RANK: Rating Gaps

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

Engagement Streaks (3+ Orders, ≤7-Day Gaps)

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top-N Products per Category

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Median Salary Without PERCENTILE

Uses: SELECT Window Functions ROW_NUMBER

Try it →
Hard Pro

Deduplicate Orders with ROW_NUMBER

Uses: SELECT Window Functions ROW_NUMBER

Try it →
Hard Pro

Sliding Window Max Revenue

Uses: SELECT Window Functions MAX

Try it →
Hard Pro

Customer Lifetime Value Pipeline

Uses: SELECT JOIN Subquery

Try it →
Hard Pro

Top Spender per Membership Tier

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Month-over-Month Revenue Growth

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Island Length Classification

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Department Salary Percentile Buckets

Uses: SELECT Window Functions NTILE

Try it →
Hard Pro

Second Highest Salary per Department

Uses: SELECT Window Functions DENSE_RANK

Try it →
Hard Pro

Year-over-Year Movie Rating Trends

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Earliest Movie per Genre

Uses: SELECT Window Functions ROW_NUMBER

Try it →
Hard Pro

Top 3 Banks Per State by Assets

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

QoQ Asset Growth — Top Banks

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Top 3 Sales Per Borough

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

YoY Sales Volume Per Borough

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Top 5 Torque Per Quality

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

Rolling Tool Wear Trend

Uses: SELECT Window Functions AVG

Try it →
Hard Pro

NPL Quarter-over-Quarter Acceleration

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Geographic Mismatch — Impossible Travel

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Peak Rolling 30-Day Spend Per Account

Uses: SELECT Window Functions Frame Clause

Try it →
Hard Pro

First-to-Second Transaction Latency

Uses: SELECT Window Functions ROW_NUMBER

Try it →
Hard Pro

Disputed Spend by Risk Tier and Category

Uses: SELECT CTE JOIN

Try it →
Hard Pro

How Concentrated Is the Spend?

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top 10% Users by Transaction Volume

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Month-over-Month Volume Growth

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top 3 Spending Categories per Country

Uses: SELECT CTE Window Functions

Try it →

Multi-step CTE questions: 13 challenges (2 free)

Two or more named steps, where a later one reads an earlier one: build the per-user table, then the per-cohort table, then the ratio. Interviewers watch whether each step has one job.

Counted from the challenge bank, September 2026. Easy first, then Medium, then Hard.

Hard Free preview

Cumulative Distinct Customers Over Time

Uses: SELECT CTE Window Functions

Try it →
Hard Free preview

Multi-CTE Revenue Pipeline

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Order Sessionization by Customer

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Engagement Streaks (3+ Orders, ≤7-Day Gaps)

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Island Length Classification

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Customer Retention Cohort

Uses: SELECT CTE MIN

Try it →
Hard Pro

QoQ Asset Growth — Top Banks

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Banks with NPL Above 2-Sigma

Uses: SELECT CTE Aggregation

Try it →
Hard Pro

3-Sigma Anomaly: Transaction Amount Outliers

Uses: SELECT CTE Aggregation

Try it →
Hard Pro

Disputed Spend by Risk Tier and Category

Uses: SELECT CTE JOIN

Try it →
Hard Pro

How Concentrated Is the Spend?

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top 10% Users by Transaction Volume

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top 3 Spending Categories per Country

Uses: SELECT CTE Window Functions

Try it →

Hard join and subquery questions: 45 challenges (3 free)

Several tables at different grains, a subquery that filters or feeds a comparison, and the anti-join behind "customers who never ordered": NOT EXISTS or LEFT JOIN … IS NULL. The trap is the fan-out, where a join multiplies rows before the aggregate counts them.

Counted from the challenge bank, September 2026. Easy first, then Medium, then Hard.

Hard Free preview

Running Total Revenue

Uses: SELECT Subquery Window Functions

Try it →
Hard Free preview

Year-over-Year Growth

Uses: SELECT Subquery Window Functions

Try it →
Hard Free preview

Multi-CTE Revenue Pipeline

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Wealthy Survivor Profile

Uses: SELECT WHERE Subquery

Try it →
Hard Pro

Employees Earning More Than Manager

Uses: SELECT JOIN WHERE

Try it →
Hard Pro

Top Spender Per Country

Uses: SELECT Subquery GROUP BY

Try it →
Hard Pro

Employees with Similar Salaries

Uses: SELECT Self-Join Non-Equi Join

Try it →
Hard Pro

Moving Average with Dynamic Window

Uses: SELECT Window Functions Frame Clause

Try it →
Hard Pro

Detect Repeat Buyers Within 7 Days

Uses: SELECT Self-Join Date Functions

Try it →
Hard Pro

Highest Fare Per Port

Uses: SELECT Subquery WHERE

Try it →
Hard Pro

Nth Highest Salary per Department

Uses: SELECT Subquery Window Functions

Try it →
Hard Pro

Correlated Subquery: Employees Above Department Median

Uses: SELECT Correlated Subquery COUNT

Try it →
Hard Pro

Recursive Team Size Rollup

Uses: SELECT Recursive CTE CTE

Try it →
Hard Pro

Top Earner Per Department

Uses: SELECT Window Functions Subquery

Try it →
Hard Pro

Consecutive IDs

Uses: SELECT JOIN Self-Join

Try it →
Hard Pro

Customer Lifetime Value

Uses: SELECT JOIN GROUP BY

Try it →
Hard Pro

Order Status Dashboard

Uses: SELECT GROUP BY Aggregation

Try it →
Hard Pro

RANK vs DENSE_RANK: Rating Gaps

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

Self-Join: Manager Salary Comparison

Uses: SELECT Self-Join LEFT JOIN

Try it →
Hard Pro

Anti-Join Pipeline: Unmatched Records

Uses: SELECT LEFT JOIN IS NULL

Try it →
Hard Pro

Department Budget Analysis

Uses: SELECT CTE Aggregation

Try it →
Hard Pro

Customers with Orders in ALL Categories

Uses: SELECT GROUP BY HAVING

Try it →
Hard Pro

Customer Lifetime Value Pipeline

Uses: SELECT JOIN Subquery

Try it →
Hard Pro

Top Spender per Membership Tier

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Recursive Org Chart Traversal

Uses: SELECT CTE Recursive CTE

Try it →
Hard Pro

Self-Join: Repeat Orders Within a Week

Uses: SELECT JOIN Date Functions

Try it →
Hard Pro

Customer Retention Cohort

Uses: SELECT CTE MIN

Try it →
Hard Pro

Earliest Movie per Genre

Uses: SELECT Window Functions ROW_NUMBER

Try it →
Hard Pro

QoQ Asset Growth — Top Banks

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

Active Properties with Permits

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Top 5 Torque Per Quality

Uses: SELECT Window Functions RANK

Try it →
Hard Pro

Failure Rate by Torque Bucket

Uses: SELECT CTE JOIN

Try it →
Hard Pro

Banks with NPL Above 2-Sigma

Uses: SELECT CTE Aggregation

Try it →
Hard Pro

NPL Quarter-over-Quarter Acceleration

Uses: SELECT Window Functions LAG

Try it →
Hard Pro

3-Sigma Anomaly: Transaction Amount Outliers

Uses: SELECT CTE Aggregation

Try it →
Hard Pro

Velocity Rule — 5+ Transactions in 5 Minutes

Uses: SELECT JOIN GROUP BY

Try it →
Hard Pro

Recursive CTE — Chargeback Chain Investigation

Uses: SELECT Recursive CTE JOIN

Try it →
Hard Pro

Cards That Never Spend at Home

Uses: SELECT JOIN GROUP BY

Try it →
Hard Pro

Two Swipes at the Same Merchant Inside a Day

Uses: SELECT Self-JOIN JOIN

Try it →
Hard Pro

Disputed Spend by Risk Tier and Category

Uses: SELECT CTE JOIN

Try it →
Hard Pro

How Concentrated Is the Spend?

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Top 10% Users by Transaction Volume

Uses: SELECT CTE Window Functions

Try it →
Hard Pro

Card Decline Rate by Plan

Uses: SELECT CASE SUM

Try it →
Hard Pro

FX Fee Take Rate by Currency

Uses: SELECT JOIN GROUP BY

Try it →
Hard Pro

Top 3 Spending Categories per Country

Uses: SELECT CTE Window Functions

Try it →

Where this shows up next

If a Hard question stalls, the fix is almost always one level down: the ranking functions page and the window functions on-ramp, CTE practice, or joins. The readiness test finds which one in ten questions.

Questions

What counts as an advanced SQL interview question?

One that needs more than one idea in the same query, typically a window function over a partition, a chain of CTEs, or an anti-join, and where the grain of the result has to be reasoned about rather than read off the question.

Are these the actual questions companies ask?

No. They are SQL Quest practice problems written around the patterns reported for data analyst, data scientist and analytics engineer screens. No company has published them.