Advanced SQL: Window Functions & CTEs for Complex Analysis Questions
Advanced SQL techniques using window functions (ROW_NUMBER, RANK, DENSE_RANK, etc.) and common table expressions (CTEs), including recursive queries, for complex data analysis, ranking and analytics patterns, cumulative totals, and multi-step data transformations within relational databases and data warehousing contexts.
HardTechnical
53 practiced
Write SQL that computes percent change vs prior period and flags statistically significant changes using a z-score approximation. Table: daily_sales(store_id, sale_date DATE, revenue NUMERIC). Return store_id, sale_date, revenue, pct_change, z_score_flag. Describe assumptions.
EasyTechnical
52 practiced
Explain the differences between ROW_NUMBER(), RANK(), and DENSE_RANK() window functions. For each function, give a short example dataset and describe the result. As a BI analyst, when would you choose one over the others for leaderboard and tie-handling scenarios?
MediumTechnical
57 practiced
Write SQL that computes a running total on a very large dataset but restricts the frame to the last 90 days for each user to limit work per row. Table: events(user_id, event_time TIMESTAMP, value NUMERIC). Return user_id, event_time, value, running_90d_total.
MediumTechnical
62 practiced
Explain how PARTITION BY affects parallelism and planner choices in databases like PostgreSQL. Provide an example where changing the partition key improves query performance for window functions on a large table.
HardTechnical
66 practiced
Explain SQL portability considerations when using advanced window features (e.g., RANGE with INTERVAL, implicit frame behavior) across PostgreSQL, BigQuery, Snowflake, and SQL Server. Provide examples of at least two features that behave differently and how you'd write portable SQL for BI use.
Unlock Full Question Bank
Get access to hundreds of Advanced SQL: Window Functions & CTEs for Complex Analysis interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.