SELECT c.id_cliente AS NIT, cl.nombre_cliente AS cliente,
cs.direccion AS Direccion, z.descripcion AS Ciudad, cs.telefono AS Telefono,
cs.nombre_contacto AS Contacto,
SUM( c.valor ) AS Cartera_Actual, cs.cupo AS Cupo_Actual
FROM cartera c
JOIN cliente_has_sucursal cs 
ON ( c.id_cliente = cs.id_cliente AND c.id_sucursal = cs.id_sucursal )
JOIN zona z ON ( cs.ciudad = z.id_zona )
JOIN cliente cl 
ON ( cl.id_cliente = cs.id_cliente AND cl.id_cliente = c.id_cliente )
WHERE c.valor >0
GROUP BY c.id_cliente
HAVING (
SUM( c.valor ) >=3000000
)
ORDER BY `cl`.`nombre_cliente` ASC
