我試圖寫一個查詢,有效地,結合了下面兩個查詢,但我認爲我有作家阻止。我試過寫一個子查詢,但無濟於事。我已經考慮過一個交叉表查詢,但我想避免任何特定的Access。我試過了一個聯盟,但是這似乎也不起作用。我高度懷疑這只是我的垃圾。我很想嘗試一下SQL PIVOT,但是我之前沒有嘗試過,並且根據我今天的行程來判斷,我懷疑我會成功。計數值的數量並返回一個列作爲
無論如何,這對我的工作的查詢是:
SELECT Operative.NAME, COUNT(*) AS [Yes to Left Tidy?]
FROM Operative INNER JOIN ([Survey Results] INNER JOIN JOBS ON [Survey Results].Job_Number = JOBS.Job_Number) ON Operative.USERID = JOBS.SCHEDULEITEMS_ASSIGNEDWORKERID
WHERE Q5 = 'yes'
GROUP BY Operative.NAME
SELECT Operative.NAME, COUNT(*) AS [No to Left Tidy?]
FROM Operative INNER JOIN ([Survey Results] INNER JOIN JOBS ON [Survey Results].Job_Number = JOBS.Job_Number) ON Operative.USERID = JOBS.SCHEDULEITEMS_ASSIGNEDWORKERID
WHERE Q5 = 'no'
GROUP BY Operative.NAME
如果你要我詳細的表結構等,請讓我知道。
你嘗試的聯合查詢,併發生了什麼? –
我想他希望Operative.NAME,count(no),count(是)在一行中,提供q5的表上的雙連接就足夠了,儘管 –
可以給我們你的表結構和預期的查詢結果請@馬特 –