InterviewStack.io LogoInterviewStack.io

SQL for Business Scenarios Questions

Ability to read and decompose business questions and translate them into correct, efficient Structured Query Language queries that answer those questions. This includes identifying the required data sources and joins, choosing between inner joins, outer joins, anti joins and existence checks, writing subqueries and common table expressions for clarity, and applying filtering with where clauses, aggregation with group by and having, and window functions for ranking, running totals, and time series calculations. Candidates should demonstrate how to implement common business analyses such as conversion funnels, retention and cohort analysis, churn and lifetime value calculations, and operational metrics by mapping metric definitions to SQL expressions and handling edge cases like null values, duplicates, and late arriving data. The description also covers writing medium complexity queries that combine multiple tables, calculating derived metrics, validating results with sample data, and considering query performance through basic optimization techniques, indexing awareness, and selective projection.

HardTechnical
72 practiced
transactions(transaction_id, customer_id, amount NUMERIC, transaction_date DATE). Write SQL to flag transactions on a given day that are anomalous: amount > median + 3 * IQR per customer over the trailing 90 days. Provide a solution that computes per-customer 90-day median and IQR and then flags today's transactions. Discuss performance considerations and options for incremental computation.
MediumTechnical
73 practiced
Explain how to design indexes for queries that frequently filter by customer_id and a date range and also order by created_at. Give examples of single-column and composite indexes, including covering indexes, and explain the trade-offs like write amplification and maintenance cost.
MediumTechnical
67 practiced
raw_events(event_id, external_id TEXT, insert_ts TIMESTAMP, payload JSONB). You find duplicate external_id rows; remove duplicates keeping the row with the latest insert_ts. Write a safe DELETE query (Postgres) using a CTE and window functions. Discuss transactional considerations for running this in production.
HardTechnical
65 practiced
survey_responses(user_id, score INT, response_date DATE). Each user can respond multiple times; for an NPS calculation over a survey window, keep the latest response per user in that window. Write SQL that computes NPS = %promoters (9-10) - %detractors (0-6). Return counts and NPS percentage. Handle users with no responses (exclude them).
EasyTechnical
54 practiced
Given query: SELECT * FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE o.created_at BETWEEN '2024-01-01' AND '2024-01-31' AND c.country = 'US'; Describe which indexes you would create to help this query and why. Mention trade-offs (write overhead, index size) and what histogram/cardinality information you would check before deciding.

Unlock Full Question Bank

Get access to hundreds of SQL for Business Scenarios interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.