mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-09 15:04:10 +02:00
fix balances view.
This commit is contained in:
@ -21,14 +21,18 @@ CREATE TABLE IF NOT EXISTS apipayments (
|
|||||||
memo text
|
memo text
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE VIEW IF NOT EXISTS balances AS
|
DROP VIEW IF EXISTS balances;
|
||||||
|
|
||||||
|
CREATE VIEW balances AS
|
||||||
SELECT wallet, coalesce(sum(s), 0) AS balance FROM (
|
SELECT wallet, coalesce(sum(s), 0) AS balance FROM (
|
||||||
SELECT wallet, sum(amount) AS s -- incoming
|
SELECT wallet, sum(amount) AS s -- incoming
|
||||||
FROM apipayments
|
FROM apipayments
|
||||||
WHERE amount > 0 AND pending = false -- don't sum pending
|
WHERE amount > 0 AND pending = false -- don't sum pending
|
||||||
|
GROUP BY wallet
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT wallet, sum(amount + fee) AS s -- outgoing, sum fees
|
SELECT wallet, sum(amount + fee) AS s -- outgoing, sum fees
|
||||||
FROM apipayments
|
FROM apipayments
|
||||||
WHERE amount < 0 -- do sum pending
|
WHERE amount < 0 -- do sum pending
|
||||||
|
GROUP BY wallet
|
||||||
)
|
)
|
||||||
GROUP BY wallet;
|
GROUP BY wallet;
|
||||||
|
Reference in New Issue
Block a user