Ver originalSELECT c.Nombre, SUM(f.Total) Total, SUM(IFNULL(p.pagado, 0)) Pagado, (SUM(f.Total)- SUM(IFNULL(p.pagado, 0))) Debe, FORMAT((SUM(f.Total)- SUM(IFNULL(p.pagado, 0))),0) TotalDebe2FROM tblcliente cINNER JOIN tblfactura f ON c.IdCliente=f.IdClienteLEFT JOIN ( SELECT NroFactura, SUM(Valor) Pagado FROM tblpagosxfactura GROUP BY NroFactura) p ON f.NroFactura = p.NroFacturaGROUP BY c.IdClienteORDER BY Debe DESCLIMIT 5