我正在使用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個表合併成一個。通常,具有相同結構的多個表格表明數據庫設計存在問題。 –