美好的一天,SQL SELECT查詢排除值
我想選擇與平均領域
SELECT
CAST(SurveyDept AS NVARCHAR(100)) as Dept_name,
CAST(SurveySubDept AS NVARCHAR(100)) as Subdept_name
AVG(SurveyReachability) as total_R,
AVG(SurveyProfessionalism) as total_P,
AVG(SurveyProactiveness) as total_Pr,
AVG(SurveyCompetence) as total_C,
AVG(SurveyResponse) as total_Re
FROM
dbo.tb_SurveyDeptInfo
GROUP BY
CAST(SurveyDept AS NVARCHAR(100)),
CAST(SurveySubDept AS NVARCHAR(100))
ORDER BY
CAST(SurveyDept AS NVARCHAR(100)),
CAST(SurveySubDept AS NVARCHAR(100))
結果看起來像這樣的一個表:
什麼我想要做的是排除具有值(轉移)和值(檢查&公用事業服務付款)的「子部門名稱」(如果存在)
所以我加了(按順序)後,下方:
WHERE Subdept_name NOT IN (SELECT *
FROM dbo.tb_SurveyDeptInfo
WHERE CAST(SurveySubDept AS NVARCHAR(100)) = 'Transfers'
OR CAST(SurveySubDept AS NVARCHAR(100)) = 'Check & Utility Service Payments')
你能勸哪裏出了問題,它不返回任何記錄
是有可能在下添加一個新的列(調查響應),此列將包含整個行本身的AVG? – user1000744