SQL
92 bites tagged SQL — interview questions with model answers, and 60-second explainers.
How would you combine customer and transaction DataFrames and describe join types?
This tests relational merging and join semantics in pandas. Answer: use pd.merge on customer_id, then groupby sum; describe inner, left, right, and outer joins by key preservation. Red flag: proposing concat without keys or conflating inner and left joins.
Model a Room one-to-many Playlist-to-Song relationship
Tests Room relational modeling. Strong answer: Song foreign key, `@Embedded` Playlist with `@Relation` to `List<Song>`, DAO wrapped in `@Transaction`. Red flag: embedding songs in Playlist or skipping `@Transaction`, which causes N+1 queries.
Design a data model for feature adoption tracking
Tests dimensional modeling for high-volume events so PMs can query Feature A not B without complex SQL. A strong answer uses an event fact table plus a materialized user-feature summary. Red flag: a wide user table with boolean columns per feature.
Explain cohort retention and write a pseudo-query for May signups
Tests cohort retention vs aggregate DAU and SQL self-joins for Week 1, 2, and 4 retention from May signups. Strong answers define cohorts by signup date, use datediff, and left-join activity. Red flag: using calendar week instead of relative signup date.
Write SQL to generate a monthly cohort retention table from raw events
Tests window functions and date truncation for cohort analysis. A strong answer finds each user's first month, counts returning users per period, and divides by cohort size. Aggregating all users without isolating acquisition month hides new-user churn.
Define and calculate Weekly Active Users (WAU) for Slack
Tests translating a business metric to a technical spec. Define 'active' by key actions (sending messages, not just opening), then `COUNT(DISTINCT user_id)` on an events table, filtering out bots and background syncs. A red flag is a generic definition.
Calculate Monthly Recurring Revenue (MRR) with SQL
This tests your ability to translate a business metric into a robust SQL query, handling time-series logic. A good answer filters for active subscriptions, sums the price, and correctly amortizes annual plans. A red flag is using incorrect date filtering.
How do you handle timezones for a global daily sales report?
This tests your ability to translate ambiguous business needs (a "day") into a robust data model. First, clarify the business definition of a day. Then, store all event times in UTC and convert to the target timezone at query time for reporting.
Calculate Daily Active Users (DAU) with SQL
This tests your ability to translate a business metric into a precise technical definition and query. A good answer defines "active," specifies the event data needed (user_id, timestamp, event_name), and uses COUNT(DISTINCT user_id).
Build a SQL query for a multi-step conversion funnel
Tests your ability to translate a product question into robust SQL. A great answer uses CTEs or left joins to count users at each step, defining the attribution model (e.g., first-touch) and time windows. A red flag is a naive query that double-counts users.
Design a User Onboarding Funnel Analysis System
This tests translating a business need into a data model and query. First, define the cohort. Then, use CTEs to find the first timestamp for each event per user. Finally, count users at each step.
Design a data model for tracking feature adoption
This tests your grasp of data warehouse star schemas for analytics. Outline a fact table for events and dimension tables for users and features, explaining how this structure enables fast, ad-hoc cohort analysis for a product manager.
Explain cohort analysis and write a retention query
Tests your grasp of user behavior metrics. First, define a cohort (e.g., May signups). Then, explain why it's better than aggregate retention. Finally, outline a query grouping users by signup week and checking for activity. A red flag is a flawed query.
Optimizing a Slow, Expensive Data Warehouse for BI Dashboards
Tests your grasp of data warehouse architecture beyond basic SQL. A great answer covers partitioning/clustering, materialized views for pre-aggregation, and cost controls. A red flag is suggesting only query rewrites or just 'adding more compute'.
How to query a monthly cohort retention table in SQL?
Tests your ability to translate a core business metric into a multi-step SQL query. A good answer finds each user's acquisition month, joins that back to their activity, and pivots the data into a cohort grid. A red flag is calculating aggregate retention.
Explain the star schema and its advantages for analytics
This tests your grasp of OLAP vs. OLTP data modeling. A great answer defines fact/dimension tables, explains how denormalization leads to fewer joins and faster queries, and contrasts this with 3NF's focus on write integrity.
How to diagnose a slow dashboard query?
This tests systematic debugging of a data problem. A good answer investigates the query plan first, then the table's physical layout (partitioning/clustering), and finally the BI tool and warehouse load. A red flag is jumping to a solution without diagnosis.
Star vs. Snowflake Schemas: Trade-offs
Tests your grasp of data warehouse design trade-offs. Define star (denormalized, fast queries) and snowflake (normalized, storage efficient) schemas. Explain the core trade-off: star's query speed vs. snowflake's storage/integrity.
How would you define and calculate Weekly Active Users (WAU)?
This tests your product sense and technical precision in defining a core business metric. A great answer defines 'active' with specific user actions, outlines the SQL/event-based calculation, and discusses pitfalls like bots and background events.
Calculate MRR from a subscriptions table using SQL
Tests your ability to translate a business metric (MRR) into a precise SQL query. A great answer filters for active subscriptions this month and sums their prices, correctly amortizing annual plans.
How do you handle timezones for a daily global sales report?
This tests your understanding of time data modeling and business requirements. A good answer stores events in UTC with a timezone identifier, then converts to the business's chosen 'day' at query time. A red flag is storing local time without context.
Calculate Daily Active Users (DAU) with SQL
This tests product sense and SQL fundamentals. Define 'active' with a core product action, describe the event data needed, then write a COUNT(DISTINCT user_id) query. A red flag is writing SQL before defining the business logic for 'active'.
How would you build a SQL query for a conversion funnel?
Tests your ability to translate a business need into a technical SQL solution. A good answer uses CTEs or LEFT JOINs to model sequential steps, counts users at each stage, and discusses attribution.
Calculate a 3-step user onboarding funnel with SQL
Tests your ability to translate a business need into a robust data query. A great answer clarifies funnel logic (attribution, timing), defines the user cohort, finds each user's first event for each step, and then calculates conversion.
Get SQL bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.