2014-05-13 119 views
0

我使用的MS Access 2010中多個記錄

我試圖通過同桌的加入不同的部分,以創建具有三列的表

數據集是

ID Date  Job Title            Count of ID 
-- --------- ------------------------------------------------------ ----------- 
1 13-May-14 Security Guards             15 
2 13-May-14 Interpreters and Translators         22 
3 13-May-14 Laborers and Freight, Stock, and Material Movers, Hand   1 
4 13-May-14 Maintenance and Repair Workers, General       23 
5 13-May-14 Protective Service Workers, All Other       54 
6 13-May-14 Logisticians             65 
7 02-Apr-14 Security Guards             88 
8 02-Apr-14 Interpreters and Translators         22 
9 02-Apr-14 Laborers and Freight, Stock, and Material Movers, Hand   44 
10 02-Apr-14 Maintenance and Repair Workers, General       77 
11 02-Apr-14 Protective Service Workers, All Other       66 
12 02-Apr-14 Logisticians              8 

和查詢是

SELECT ctrjob.[Job Title], ctrjob.[Count of ID], 

(Select ctrjob.[Count of ID] from ctrjob 
where ctrjob.[Job Title] = ctrjob.[Job Title] and ctrjob.[Date] = #4/2/2014#) 

FROM ctrjob where [ctrjob].[Date] = #5/13/2014# ; 

我想我的成品表創建一個表放置麻木呃2014​​年5月13日每個職位的承包商旁邊的數字從2014年4月2日。目標是比較工人數量的變化。

但我不斷收到錯誤消息

最多一個記錄可以由子查詢

返回,但我要的是,它從另一個返回一個相應的記錄日期。每次執行它應該只返回2014年4月2日工作類別X中的編號。

我不想使用變換/交叉表,因爲完整數據集的日期太多,我想使用表單在最後切換日期。職位名單在所有日期都是相同的。我使用的MS Access 2010中

回答

1

而不是一個子查詢,使用聯接:

SELECT a.[Job Title], a.[Count of ID], b.[Count of ID] 
FROM ctrjob a INNER JOIN 
    ctrjob b ON a.[Job Title] = b.[Job Title] 
WHERE a.Date = #4/2/2014# AND 
     b.Date = #5/13/2014# 
+0

我可以使用加入?所有原始數據都在一個表格中。 – user2907249

+0

是的,你可以;它被稱爲自連接。 –