2017-08-16 9 views
2

我想檢查表「T2」的3個字段的值一起出現在表「T1」每個用戶的東西加入這樣的:麻煩建立一個SQL連接

![Tentative of illustration] 1

預期的結果:

enter image description here

這是可能的呢?如果是的話,你可以幫忙建立一個查詢嗎?

謝謝

Link to the MS access file:

+0

是否有用戶字段T1? – Parfait

+0

不,T1中的每條記錄都代表不同系統特權的組合,不應將這些特權一起授予同一用戶。因此,在T2中,我擁有所有用戶和所有權限,並且我正在嘗試確定誰有*禁止*組合。 –

+0

T1中的行如何不同?是否有其他現場指示器未顯示? – Parfait

回答

1

假設基礎上發佈的例子:只有3個因素和因素在T1的任何領域。

需要在每個表中的唯一標識符字段,自動編號應該服務。

查詢:T1_UNION(A UNION查詢必須輸入(或在查詢生成器的SQLView複製/粘貼)。)
SELECT RecID_T1, "R1" AS Cat, R1 AS Data FROM T1 UNION SELECT RecID_T1, "R2", R2 FROM T1 UNION SELECT RecID_T1, "R3", R3 FROM T1;

查詢:T2_CROSSTAB
TRANSFORM First(T2.R) AS FirstOfR SELECT T2.U FROM T2 GROUP BY T2.U PIVOT DCount("*","T2","U='" & [U] & "' AND RecID_T2<" & [RecID_T2])+1;

查詢:
SELECT T2_CROSSTAB.U, DLookUp("Data","T1_UNION","Data='" & [1] & "'") AS IsMatch1, DLookUp("Data","T1_UNION","Data='" & [2] & "'") AS IsMatch2, DLookUp("Data","T1_UNION","Data='" & [3] & "'") AS IsMatch3 FROM T2_CROSSTAB WHERE ((Not (DLookUp("Data","T1_UNION","Data='" & [1] & "'")) Is Null) AND (Not (DLookUp("Data","T1_UNION","Data='" & [2] & "'")) Is Null) AND (Not (DLookUp("Data","T1_UNION","Data='" & [3] & "'")) Is Null));

使用Joe C的想法,CROSSTAB是不需要的。

查詢:Data_GROUPED
SELECT T2.U, T2.R FROM T2 INNER JOIN T1_UNION ON T2.R = T1_UNION.Data GROUP BY T2.U, T2.R ORDER BY T2.U;

查詢:
SELECT Data_GROUPED.U, Count(Data_GROUPED.R) AS CountOfR FROM Data_GROUPED GROUP BY Data_GROUPED.U HAVING (((Count(Data_GROUPED.R))=3));

+0

謝謝,但MS Access似乎不支持這些操作。與鏈接到文件或預期結果的另一個屏幕截圖 –

+0

我在MS Access中構建了表和查詢 - 所有作品都必須在查詢生成器的SQLView中鍵入(或複製/粘貼)查看我編輯的答案,更改爲需要兩種方法的唯一ID – June7

+0

令人驚歎!!我可以在那裏完成表單,非常感謝! –