0
以下代碼在MS Access中正常工作。但是,我試圖添加更多的左連接。我的左連接將加入查詢而不是表格。多個連接左連接訪問/子查詢
希望這是有道理的。
欣賞的幫助
SELECT
a.[business unit],
b.[Total Colleagues in DMS],
Sum(IIf([a].[Session Date] Is Not Null,1,0)) AS [Total Bookings],
Sum([a.Has Booking been cancelled (Yes/No)]) AS [Total Cancellations],
(Sum(IIf([a].[Session Date] Is Not Null,1,0))-Sum([a.Has Booking been cancelled (Yes/No)])) AS [Net Bookings],
Sum([a.lookup_attended]) AS Attended,
(b.[Total Colleagues in DMS]-(Sum(IIf([a].[Session Date] Is Not Null,1,0))-Sum([a.Has Booking been cancelled (Yes/No)]))) AS [Unbooked Spaces]
FROM
everything AS a
LEFT JOIN
(
SELECT
a.[business unit], count(*) AS [Total Colleagues in DMS]
FROM
(
SELECT DISTINCT
a.lookup_id,
A.[BUSINESS UNIT]
FROM
EVERYTHING AS a
WHERE
(a.status<>"leaver" Or a.status<>"Not in scope")
And
A.PROJECT Is Null
) AS [%$##@_Alias]
GROUP BY
a.[business unit]
) AS b
ON
a.[business unit] = b.[business unit]
WHERE
(
((a.status)<>"leaver" Or (a.status)<>"not in scope")
GROUP BY
a.[business unit],
b.[Total Colleagues in DMS],
b.[business unit];
需要後在提問時提供更多信息,例如:查詢的名稱是什麼試圖加入?它與列出的現有表格有何關係?一旦你添加了這個查詢,那麼這個連接和其他表之間的關係可能會被關閉。 – xQbert
有什麼不適合呢?重新格式化你的SQL之後,你的'WHERE'語句中缺少''''。你只是遇到語法錯誤?你能發佈確切的錯誤信息,如果有的話? –
表的確可以是查詢(派生表,VIEW,存儲查詢對象)。要加入第三個表格,您需要將前兩個表格放在parens中,例如'SELECT * FROM(T1加入T2在T1.id = T2.id)JOIN T3 ON T1.id = T3.id'(注意優化器不需要遵守指定的順序)。 – onedaywhen