tengo esta consulta de postgrest:
SELECT
u.type AS "userType",
u.state AS "state",
u.email AS "email",
u.cellphone AS "cellphone",
s.name AS "storeName",
s.idshop AS "id",
u.iduser AS "idu",
b.name AS "bank",
ba.number AS "accountNumber",
h.name AS "accountHolder",
h.document AS "documentHolder",
c.alias AS "coin"
FROM "banksAccounts" AS ba
INNER JOIN holders AS h ON ba.idholder = h.idholder
INNER JOIN coins AS c ON ba.idcoin = c.idcoin
INNER JOIN banks AS b ON ba.idbank = b.idbank
RIGHT JOIN shops AS s ON ba.idbankaccount = s.idbankaccount
LEFT JOIN "usersShops" AS us ON s.idshop = us.idshop
RIGHT JOIN users AS u ON u.iduser = us.iduser
WHERE s.idshop = '59';
Lo que quiero es añadirle a esta consulta otra tabla "paymentsPending" que depende de la tabla "shops"; de "paymentsPending" necesito contar los pagos pendientes de la tienda y su cantidad total de dinero. Estas tablas se relacionan con una llave foranea "idShop" que la tiene "paymentsPending", esta tabla tiene el campo "value" que es la cantidad de dinero. Gracias