0

I have this query to count the times documentador is repeated in each table

(select count(documentador) AS count, documentador from impo_expo GROUP BY documentador order by documentador) UNION ALL
(select count(documentador), documentador from prov_compr GROUP BY documentador order by documentador) UNION ALL
(select count(documentador), documentador from pedimento GROUP BY documentador order by documentador) UNION ALL
(select count(documentador), documentador from partidas GROUP BY documentador order by documentador) order by documentador asc

OUTPUT:

count   documentador
2          Imelda
4          Imelda
2          Imelda
1          Imelda
2          Juan Enrique
1          Juan Enrique
1          Juan Enrique
1          Juan Enrique
2          Raul

How can i combine them to have something like this?

count   documentador
9         Imelda
5       Juan Enrique
2          Raul

1 Answer 1

1

How about a "group by" and a "sum" around your query? Something like this:

select documentador, sum(count) as thesum from (
(select count(documentador) AS count, documentador from impo_expo GROUP BY documentador) UNION ALL
(select count(documentador), documentador from prov_compr GROUP BY documentador) UNION ALL
(select count(documentador), documentador from pedimento GROUP BY documentador) UNION ALL
(select count(documentador), documentador from partidas GROUP BY documentador) order by documentador asc
) a group by documentador order by thesum desc
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.