1
我需要從子查詢中的外部查詢中訪問別名,如此代碼。除非它不起作用。有沒有辦法做到這一點? 我的目標是爲每個OwnerIdName創建這些聚合函數,這是我能想到的唯一方法。 我在SQL Server 2008工作訪問子查詢中的別名
感謝
SELECT Incident.OwnerIdName as OIN
,(SELECT COUNT(*)
FROM Incident
WHERE CreatedOn BETWEEN '2011/1/1' AND '2011/1/31'
AND Incident.OwnerIdName = OIN) as CasesOpened
,(SELECT COUNT(*)
FROM IncidentResolution
WHERE ActualEnd BETWEEN '2011/1/1' AND '2011/1/31'
AND Incident.OwnerIdName = OIN) as CasesClosed
FROM Incident
謝謝。我沒有想到這一點。 :) – Aaron