-- name: GetCumultativeBalances :many
SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
       COALESCE(ass.amount, 0)::decimal(12,2) as assignments,
       COALESCE(tra.amount, 0)::decimal(12,2) as transactions
FROM assignments_by_month as ass
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
WHERE COALESCE(ass.budget_id, tra.budget_id) = @budget_id
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount);