Skip to content
Advertisement

How to get counts + sum of counts in MS Access?

I have a table ‘workers’ which contains data like

name    |   category
----------------------
Steve   |   A
Anne    |   B
Linda   |   A

… etc

I want to get an overview of categories (counts of categories) PLUS the whole count.

A query of

SELECT category, COUNT(category) AS number_of_people
FROM workers
GROUP BY category

gets me this far:

category    |   number_of_people
----------------------------------
A   |   2
B   |   1

But my desired output would be something like:

category    |   number_of_people
----------------------------------
A   |   2
B   |   1
-----------------------------------
TOTAL   |   3

I’m using MS Access.

Advertisement

Answer

Use union

SELECT category, COUNT(category) AS number_of_people
FROM workers
GROUP BY category
union
SELECT 'total', COUNT(category) AS number_of_people
FROM workers
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement