Show Account Balance

This commit is contained in:
2021-12-02 21:29:11 +00:00
parent 276fdb4ade
commit 6f8a94ff5d
4 changed files with 19 additions and 9 deletions

View File

@ -5,5 +5,7 @@ VALUES ($1, $2)
RETURNING *;
-- name: GetAccounts :many
SELECT accounts.* FROM accounts
WHERE accounts.budget_id = $1;
SELECT accounts.id, accounts.name, SUM(transactions.amount) as balance FROM accounts
WHERE accounts.budget_id = $1
AND transactions.date < NOW()
GROUP BY accounts.id, accounts.name;