我正在使用MS Access 2010.数据库有一组12个相同的设备表,每个公司有12个不同的部门。该表跟踪负责设备的人员(资源)需要采取的操作。我有一个简单的查询来计算具有各种状态的资源数量。它看起来如下:跨多个表的聚合SQL查询
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个表合并成一个。通常,具有相同结构的多个表格表明数据库设计存在问题。 –