SQL interview questions you can run.
A SQL interview for an analyst or analytics engineer role rarely asks for syntax. It gives you a business problem and a few tables, and checks whether you get the grain, the join, and the definition right. These 10 questions are written that way. Each one runs in your browser on linked tables, and your result is checked.
Free · No signup to run or check
Four things, in nearly every SQL screen.
- Grain
- What one row means in each table, and what it means after your join. Most wrong totals are a row counted twice.
- Joins that keep the right rows
- When a LEFT JOIN is needed, and where a filter goes so that it does not quietly turn into an inner join.
- Window functions
- Ranking inside a group, comparing a row with the one before it, and running totals. These come up in almost every live screen.
- Definitions
- Which rows belong in the denominator, and what counts as late, churned, or repeat. Say the definition before you write the query.
10 questions, from a warm-up to the ones that decide the round.
Each entry shows the question as you would hear it, the skill it tests, and the mistake that most often fails it. Try the question before you read the mistake.
Double charges, or retries?
Finance has noticed that some orders have more than one row in payments and is worried customers were charged twice.
- What it tests
- GROUP BY with HAVING, and reading the result before answering
- The mistake that fails it
- Reporting every order with two payment rows as a double charge
Conversion rate without losing the leads that did not convert
Marketing wants the share of leads that became purchases for each channel.
- What it tests
- LEFT JOIN, and where a filter on the joined table belongs
- The mistake that fails it
- Filtering conversion_type in WHERE, which removes every lead that never purchased
Reconcile payments and refunds by order status
The finance team wants to tie order status to money. For each order_status, show what was collected and what was returned.
- What it tests
- Aggregating to a shared grain before joining
- The mistake that fails it
- Joining orders to payments and refunds in one step, which repeats rows and inflates both totals
Second-highest salary in each department
The classic ranking question, on tables you can query. For each department, find the second-highest base salary among active employees.
- What it tests
- Window functions, and the difference between ROW_NUMBER, RANK, and DENSE_RANK
- The mistake that fails it
- Using ROW_NUMBER, which returns the top salary again when two people share it
Top two products in each category
The merchandising team wants the two best-selling products in every category.
- What it tests
- Top N per group with a window function over an aggregate
- The mistake that fails it
- ORDER BY revenue with LIMIT 2, which returns two products overall instead of two per category
Running spend against budget
A campaign manager wants to see how quickly campaign 'CMP0001' used its budget.
- What it tests
- Running totals with a window frame
- The mistake that fails it
- Leaving out ORDER BY in the window, which returns the campaign total on every row
Which suppliers deliver late?
Operations wants to know which suppliers deliver late most often.
- What it tests
- Choosing the denominator, and a minimum sample size
- The mistake that fails it
- Dividing by all purchase orders, including ones that have not arrived yet
Revenue fell. Show the month-over-month change
Leadership says revenue fell during 2024 and wants to see when.
- What it tests
- LAG, and the order in which a filter and a window function run
- The mistake that fails it
- Filtering to 2024 before calling LAG, which leaves January with nothing to compare against
Monthly churn rate, with the right denominator
The board wants a monthly churn rate for 2025. Last quarter's figure was challenged because nobody could say what it had been divided by.
- What it tests
- Building a month spine, and point-in-time counts
- The mistake that fails it
- Dividing cancellations by all subscriptions ever created instead of those active at the start of the month
How long until a customer orders again?
The retention team wants to know how long customers wait between orders, by customer segment.
- What it tests
- LAG partitioned by customer, and date arithmetic
- The mistake that fails it
- Averaging per customer and then averaging those averages, which gives a different number from the average gap
Treat each one like the live screen.
- 01
Say the definition first
Before writing anything, state what one row of your result is and what the metric counts. In an interview this is where most of the marks are.
- 02
Give yourself fifteen minutes
Write and run the query without hints. Look at the rows it returns and ask whether the numbers are plausible before you check it.
- 03
Explain what could go wrong
Name the assumption your query depends on, such as one payment per order or no missing months. Then read the worked answer.
The rest of the interview loop.
- Take-home caseRevenue fell last month
A full take-home assignment on the same e-commerce tables, with a reference solution to compare against.
- Question bank50 analytics engineer interview questions
Fifty questions beyond the SQL screen, with answers: data quality, validation, reporting, and how the role is measured.
- dbt rounddbt interview questions and answers
Fundamentals, modeling, tests and deployment, and scenario-based questions, with answers.
- Interview kitThe analytics engineering interview kit
The four rounds of the loop, with worked SQL and modeling answers and a seven-day drill plan.
- RefresherSQL window functions, with examples
ROW_NUMBER, RANK, LAG, and frames. Five of the ten questions here need one of them.
- HubAll interview preparation
Portfolio walkthroughs, behavioral questions, and the mistakes that end interviews early.
About this question set
- What SQL is asked in an analytics engineer interview?
- Mostly joins, aggregation, and window functions applied to a business question: reconciling two tables, ranking within a group, comparing a month with the one before it, and computing a rate with the right denominator. Interviewers pay more attention to whether you state the grain and the definition than to whether you remember a function name.
- Which SQL dialect do these questions use?
- They run on SQLite in your browser. The joins, CTEs, and window functions are standard SQL and work the same way in BigQuery, Snowflake, and Postgres. Date handling is the part that differs between engines: these answers use substr, date, and julianday where a warehouse would use DATE_TRUNC and DATEDIFF or DATE_DIFF.
- Do I need an account to answer them?
- No. Every question runs and is checked without an account. A free account adds hints, keeps track of what you have solved, and shows the worked answer once you have attempted a question.
- Is the data real?
- It is synthetic, generated to behave like business tables: orders with retried payments and partial refunds, subscriptions that cancel, purchase orders that arrive late. Each question runs on a linked sample of one of the free datasets on this site, and the full files can be downloaded for more practice.
- How is an answer checked?
- Your query runs in the browser and its first ten rows are compared with the expected result, in order. Column names do not have to match, but the columns must be in the order the question lists them and the rows must be sorted as asked.
