Skip to content

SQL interview questions for data analysts

Practice realistic SQL scenarios with answer criteria, validation checks and questions to ask about the role.

Use these suggested interview exercises to practice explaining assumptions, methods and validation. They are not a list of questions guaranteed to appear in an interview. The employer’s current requirements and assessment instructions take precedence.

Before you practice

Read the job description. Identify the responsibilities you would own. Ask about the assessment format, time limit, data, allowed tools and AI-assistance policy. Practice with public or synthetic data, and be ready to explain a step without relying on an assistant’s output.

How would you count paid orders for every customer?

Practice scenario: Use customers(customer_id) and orders(order_id, customer_id, status). Include customers with zero paid orders. Assume order_id is unique, and explain what changes if it is not.

What to explain: Use a LEFT JOIN with the paid-status condition in the join, then COUNT the matched order_id rather than COUNT(*). For example: SELECT c.customer_id, COUNT(o.order_id) AS paid_orders FROM customers c LEFT JOIN orders o ON o.customer_id = c.customer_id AND o.status = 'paid' GROUP BY c.customer_id. Check uniqueness before relying on the count.

How would you get the latest record per account?

Practice scenario: Events have account_id, event_time and event_id. Two events can share a timestamp. Explain a deterministic selection.

What to explain: Partition by account and order by event_time plus an agreed tie-breaker such as event_id. Select the first ranked row using a subquery or supported syntax. Define null and time-zone handling. MAX(event_time) alone does not identify the complete latest row.

How would you validate a conversion rate?

Practice scenario: The team wants purchases divided by visits, but events can contain duplicates and bots. Explain the query design before writing SQL.

What to explain: Define the visitor or session unit, eligibility, conversion window and exclusions. Deduplicate with a documented identity rule and preserve the denominator. Check sample cases including no purchases and missing events. A query that executes can still answer a different question from the agreed metric.

Review your answer

Check whether you defined the question, justified the method and proposed a way to verify the result. Include a failure case and a limitation. Our suggested rubric assesses reasoning and evidence; it is not an employer’s official scoring system.

Questions for the interviewer

  • Which deliverable would I own, and who reviews it?
  • What data-quality or operational problems does the team currently face?
  • How do you assess success and support learning in this role?

Sources and next steps

Sources checked on October 2, 2026. Follow the linked documentation for current requirements.

PostgreSQL SQL tutorial

Frequently asked questions

© Dataaxy. All rights reserved.Job data is gathered from publicly available sources or contributed by users.