如何获取计数+ MS Access中的计数总和?

时间:2019-07-12 08:16:50

标签: sql ms-access

我有一个表格'workers',其中包含类似的数据

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

...等等

我想大致了解类别(类别数)以及整个计数。

查询

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

将我带到这里:

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

但是我想要的输出将是这样的:

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

我正在使用MS Access。

1 个答案:

答案 0 :(得分:1)

使用联合

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