InterviewStack.io LogoInterviewStack.io

SQL Scenarios Questions

Advanced SQL query design and optimization scenarios, including complex joins, subqueries, window functions, common table expressions (CTEs), set operations, indexing strategies, explain plans, and performance considerations across relational databases.

MediumTechnical
29 practiced
Explain expression (functional) indexes, partial indexes, and covering indexes. Provide concrete examples: index on lower(email) for case-insensitive lookup, a partial index for status = 'active', and a covering index using INCLUDE columns. For each example explain when it is useful in BI workloads and what trade-offs exist.
HardTechnical
53 practiced
Write a single SQL query (Postgres / standard SQL) to find the top 3 products with the largest single-day consecutive percentage growth observed across any 7-day window in the past year. Input table: sales(product_id int, sale_date date, amount numeric). The query should compute day-over-day percent changes within moving 7-day windows, find the maximum consecutive-day jump per product, and return the top 3 products by that metric. Explain your approach and edge-case handling (zero sales days).
EasyTechnical
34 practiced
Explain the differences between common table expressions (CTEs) and subqueries in terms of readability and optimizer behavior. In PostgreSQL versions prior to v12, CTEs acted as optimization fences—what does that mean and when would you prefer a subquery instead of a CTE for BI queries?
MediumTechnical
26 practiced
As a BI analyst you must implement Slowly Changing Dimension Type 2 (SCD2) for a customer dimension. Given dim_customer(customer_sk int, customer_id int, name text, address text, effective_from date, effective_to date, is_current boolean) and a staging table staged_customers(customer_id, name, address, change_ts), write SQL to upsert staged changes into dim_customer so that history is preserved and the current row is marked correctly. Explain how to handle back-dated changes.
HardSystem Design
29 practiced
Design an architecture to support consistent, near-real-time BI reports while minimizing load on the OLTP system. Include replication, change data capture (CDC), read replicas, ELT vs ETL, and query routing. Discuss latency, consistency models, cost considerations, and failure modes.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.