I have a main table with one record, and in the other two tables there can be several records that depend on the record in table 1.
I need you to show me only 1 record as it appears in image 1, but adding 3 more columns corresponding to:
1 - Sum of the values of the 'valued' column in table 2 that coincide with the primary key of table 1 and the number of rows added.
2 - Total records in table 3 that match the primary key in table 1.
I have this sql but the sum does not work for me:
SELECT count(DISTINCT(p.idpagos)) as pagos, sum(valorabonado), count(DISTINCT(e.identrada)) FROM pagoperiodico pg
INNER JOIN pagos p USING(idpago)
INNER JOIN entrada e ON pg.idpago=e.idpago
WHERE pg.idpago=7334
GROUP BY pg.idpago