When would you choose a CTE over a subquery, and what are the trade-offs for analytical queries?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Overview: Asks when to write a common table expression instead of a subquery in analytical SQL. Tests reasoning about readability, reuse within a query, recursion, and how query optimizers inline or materialize CTEs and what that does to performance.