【发布时间】:2016-01-17 08:09:06
【问题描述】:
我使用的是 MS Access 2010。该数据库有一组 12 个相同的设备表,一个用于公司中 12 个不同部门中的每一个。该表跟踪需要由负责设备的人员(资源)采取的行动。我有一个简单的查询来计算具有各种状态的资源的数量。它看起来如下:
SELECT dept1.actions.resource, dept1.action.status, Count(*) AS status_count
FROM dept1.action
GROUP BY dept1.action.status, dept1.action.resource;
每个表格如下所示:
equip_id, text
resource, number (id of the resource who is responsible for the equipment)
status, number (id of the status of the action that the resource needs to do)
查询结果如下:
resource status status_count
1 1 63
2 1 79
5 1 16
6 1 3
0 3 1
1 3 1180
2 3 64
3 3 61
5 3 1
6 3 2
7 3 12
0 4 4
例如,第一行显示资源 1 有 63 件状态为 1 的设备。第二行显示资源 2 有 79 件状态为 1 的设备……以此类推。
我需要的是一个聚合查询,它为所有资源和状态组合提供公司级别的总计,即完全相同的结果表,只是 status_count 列的数字要大得多。
感谢您提供的任何帮助。
【问题讨论】:
-
这是 MS Access 中的一个困难查询。您应该将 12 个表合二为一。通常,具有相同结构的多个表表明数据库设计存在问题。
标签: sql ms-access ms-access-2010