Buen dia, En mi consulta sql tengo 2 datos found y total, en el found mando las eps que tienen mayor a 40 trabajadores y a lo menores de 40 les puse otros, lo que necesito hacer es sumar todos los que dicen otros y esta suma agruparla en "otros"
Esta es mi consulta
SELECT fund, total
FROM (
(
SELECT pr_employees.eps_id, pr_funds.fund, COUNT(*) AS total, count(*) AS visible
FROM pr_employees
INNER JOIN pr_funds ON pr_funds.id = pr_employees.eps_id
WHERE pr_employees.status = 1
GROUP BY pr_employees.eps_id
HAVING visible > 40
ORDER BY total ASC
)
UNION ALL
(
SELECT pr_employees.eps_id, 'OTROS' AS fund, COUNT(*) AS total, count(*) AS visible
FROM pr_employees
INNER JOIN pr_funds ON pr_funds.id = pr_employees.eps_id
WHERE pr_employees.status = 1
GROUP BY pr_employees.eps_id
HAVING visible < 40
ORDER BY total ASC
)
) AS afp
ORDER BY total DESC
Este es el resultado de mi consulta