mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-19 09:54:21 +01:00
fix balances view.
This commit is contained in:
parent
b4426ba021
commit
8d9ab6cc77
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user