SUM with WHERE filter across a JOIN
Quick one for the cash forecast — total SaaS vendor spend YTD 2025. Join `fact_transactions` to `dim_vendors` on vendor_id where category is 'SaaS'. Only posted entries. One number, call the column `total_saas_spend`.
Each hint you reveal reduces the XP you can earn. Try the query first.
JOIN `fact_transactions` t to `dim_vendors` v on `t.vendor_id = v.id`. Wait — the column in `dim_vendors` is `vendor_id`.
Filter: `v.category = 'SaaS'`, `t.posted = 1`, and year = 2025 using `EXTRACT(YEAR FROM t.txn_date::date) = 2025`.
`SELECT SUM(t.amount) AS total_saas_spend ...` — one row, one column.