Chapter 7 · CTEs
02. Monthly New Account Trend with CTE
Medium20 XPFinance
The growth team wants a monthly trend of new account openings. Use a CTE to extract the month from opened_at and count accounts per month. In the main query, also compute a running total of accounts opened using a window function. Return month, monthly_count, and cumulative_count. Sort by month.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- account_typeTEXT
- balanceREAL
- currencyTEXT
- opened_atTEXT
- statusTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.