Simplify query by using COALESCE

This commit is contained in:
jacob1123 committed 2022-04-14 20:21:55 +00:00
1 parent 0e84cdfa5f
commit 88e1dbdfde
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -4,5 +4,5 @@ SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
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 (ass.budget_id IS NULL OR ass.budget_id = @budget_id) AND (tra.budget_id IS NULL OR tra.budget_id = @budget_id)
WHERE COALESCE(ass.budget_id, tra.budget_id) = @budget_id
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount);