Practical Analytics And SQL Fluency
Asked of: Product Manager
Last updated
What's being tested
Demonstrates practical SQL metric translation: turn a product question into correct, auditable queries that answer “who,” “when,” and “how much.” Interviewers check clarity on deduplication, time-windowing, cohort/funnel logic, and sensible performance tradeoffs for large tables.
Patterns & templates
-
Last-event-per-entity using
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY ts DESC)to dedupe; filterrow_num = 1; watch ties. -
Session / funnel counts: event-level
COUNT(*)thenCOUNT(DISTINCT user_id)per step; useCASE WHEN+GROUP BYfor step conversion rates. -
Rolling/lag analysis with
LAG(col) OVER (PARTITION BY user_id ORDER BY ts)to compute time-between-events or churn triggers. -
Time bucketing via
DATE_TRUNC('day', ts)orTIMESTAMP_TRUNCforDAU/WAU/MAU; be explicit about timezone conversion. -
Cohort retention: cohort by
MIN(event_date), thenLEFT JOINback on users to compute week N retention; prefer CTEs (WITH) for readability. -
**Avoid SELECT *** on wide tables; filter early with indexed predicates and limit scan range (
WHERE ts BETWEEN), or sample (TABLESAMPLE) for prototyping. -
Use
COUNT(DISTINCT ...)sparingly — it's correct but expensive at scale; consider approximate functions (APPROX_COUNT_DISTINCT) if acceptable.
Common pitfalls
Pitfall: Double-counting by grouping on event_id instead of user_id leads to inflated engagement metrics; always validate numerator/denominator entity alignment.
Pitfall: Using local timestamps without normalizing causes off-by-one-day cohort errors across timezones; declare and apply a canonical timezone.
Practice these
The practice cards below cover the canonical SQL/analytics variants — solve all of them and time yourself.
Related concepts
- Analytical Data Modeling For Banking Metrics
- SQL AnalyticsData Manipulation (SQL/Python)
- SQL Product AnalyticsData Manipulation (SQL/Python)
- SQL Analytical Querying And Data ModelingData Manipulation (SQL/Python)
- SQL And Python Data ManipulationData Manipulation (SQL/Python)
- Behavioral Storytelling And Tradeoff CommunicationBehavioral & Leadership