InterviewStack.io LogoInterviewStack.io

SQL for Data Analysis Questions

Using SQL as a tool for data analysis and reporting. Focuses on writing queries to extract metrics, perform aggregations, join disparate data sources, use subqueries and window functions for trends and rankings, and prepare data for dashboards and reports. Includes best practices for reproducible analytical queries, handling time series and date arithmetic, basic query optimization considerations for analytic workloads, and when to use SQL versus built in reporting tools in analytics platforms.

HardSystem Design
57 practiced
Design an architecture to support a near real-time dashboard with 5-minute freshness using SQL-backed storage. Discuss streaming ingestion, small-window aggregations, incremental materialized views or pre-aggregations, handling late/deduplicated events, and the trade-offs between latency, consistency, and cost.
HardTechnical
72 practiced
Explain causes of join cardinality misestimates that lead to poor query plans (examples: stale statistics, correlated columns, data skew). For each cause, propose SQL-level mitigations and DBA fixes (e.g., ANALYZE, extended statistics). Give a concrete example where rewriting a query results in a better plan.
HardTechnical
57 practiced
Implement first-touch, last-touch, and a simple time-decay attribution model in SQL. Tables:
touchpoints(user_id INT, channel TEXT, touch_time TIMESTAMP)
conversions(conversion_id INT, user_id INT, conversion_time TIMESTAMP, revenue NUMERIC)
Write SQL that attributes conversion revenue to channels for each conversion under the three attribution rules and discuss assumptions and limitations of pure-SQL attribution.
HardTechnical
97 practiced
You need to aggregate global events into a business day defined as 04:00 - 03:59 local time for each user. Events are stored as UTC timestamps and each user has an `user_timezone` IANA name in a `profiles` table. Write SQL (Postgres) to assign the correct local business date for each event, handling DST transitions. Explain performance and trade-offs of joining on user_timezone strings vs precomputing local_date.
HardTechnical
55 practiced
Describe how to implement an idempotent incremental ETL using SQL `MERGE` (or `INSERT ... ON CONFLICT`) that supports exactly-once semantics for ingesting incremental batches which might be replayed. Include handling deletes (tombstone records), transaction boundaries, and concurrency control strategies to avoid duplication or inconsistent state.

Unlock Full Question Bank

Get access to hundreds of SQL for Data Analysis interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.