If you could give me a hand. I am trying to perform a query to get a count of records that are in the activated table that belong to the point of sale 2 and at the same time the total of their records in number, but it takes up to 45 seconds in answer for the amount of information. Is there a more efficient way to do it? Thanks
SELECT cr.nombre, (SELECT COUNT(n.id)
FROM numero n
INNER JOIN carrier c ON c.id = n.carrier_id
INNER JOIN cliente cl ON cl.id = n.cliente_id
INNER JOIN clave_cliente cc ON cc.cliente_id = cl.id
WHERE c.id = cr.id
AND cc.puntoVenta_id = 2
GROUP BY cr.nombre) AS total,
(SELECT COUNT(a.id)
FROM numero n
INNER JOIN activado a ON a.numero_id = n.id
INNER JOIN carrier c ON c.id = n.carrier_id
INNER JOIN cliente cl ON cl.id = n.cliente_id
INNER JOIN clave_cliente cc ON cc.cliente_id = cl.id
WHERE c.id = cr.id
AND cc.puntoVenta_id = 2
GROUP BY cr.nombre) AS activados
FROM carrier cr
WHERE cr.activo = TRUE;