Combine CTE, conditional aggregation, windows, and LEFT JOIN in one query
Final boss. One query, by year-quarter 2023-2025: `year`, `quarter`, `revenue`, `cogs`, `opex`, `gross_profit` (revenue - cogs), `operating_income` (gross_profit - opex), `opex_budget` (summed from fact_budgets for that quarter), `budget_variance` (opex - opex_budget). Use LOWER() for the account_type filter. Posted only. Sort year, quarter.
Each hint you reveal reduces the XP you can earn. Try the query first.
Build a CTE for revenue/COGS/OpEx using CASE-inside-SUM, grouped by year-quarter.
Build another CTE for quarterly OpEx budget from fact_budgets (sum per quarter by EXTRACT).
LEFT JOIN the two CTEs on (year, quarter). Compute gross_profit, operating_income, budget_variance in the final SELECT.