Add query to find problematic transactions

This commit is contained in:
2022-04-22 18:31:31 +00:00
committed by Gitea
parent c595f016b8
commit 43a4647d74
2 changed files with 120 additions and 1 deletions

View File

@ -45,4 +45,19 @@ AND accounts.id = transactions.account_id;
-- name: GetTransactionsByMonthAndCategory :many
SELECT *
FROM transactions_by_month
WHERE transactions_by_month.budget_id = @budget_id;
WHERE transactions_by_month.budget_id = @budget_id;
-- name: GetProblematicTransactions :many
SELECT *
FROM transactions
LEFT JOIN accounts
ON transactions.account_id = accounts.id
LEFT JOIN transactions AS otherGroupTransaction
ON transactions.group_id = otherGroupTransaction.group_id
AND transactions.id != otherGroupTransaction.id
AND transactions.account_id != otherGroupTransaction.account_id
LEFT JOIn accounts AS otherGroupAccount
ON otherGroupTransaction.account_id = accounts.id
WHERE transactions.category_id IS NULL
AND accounts.on_budget
AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget);