我收到关键字'WHERE'
附近的错误,语法不正确我想要做的就是使用另一个表中的一些列
SELECT unitCode, studentID, s.studentFName
FROM Student As S Right outer Join
(SELECT unitCode, studentID,
SUM(CASE WHEN subStatus = 'Yes' THEN 1 ELSE 0 END) AS CountYes,
SUM(CASE WHEN subStatus = 'No' THEN 1 ELSE 0 END) AS CountNo
FROM Assignment
GROUP BY unitCode, studentID)
WHERE (CountNo > 0) AND (CountYes = 0) AND s.studentID = assignment.studentID
答案 0 :(得分:3)
您的联接缺少其ON clause
,并且子选择缺少别名:
SELECT
unitCode, studentID, s.studentFName
FROM
Student As S
Right outer Join
(
SELECT
unitCode, studentID,
SUM(CASE WHEN subStatus = 'Yes' THEN 1 ELSE 0 END) AS CountYes,
SUM(CASE WHEN subStatus = 'No' THEN 1 ELSE 0 END) AS CountNo
FROM
Assignment
GROUP BY unitCode, studentID
) as assignment
on s.studentID = assignment.studentID
WHERE
(CountNo > 0) AND (CountYes = 0)
;
答案 1 :(得分:2)
子选择必须在SQL Server中有别名。
改变这个:
OUTER JOIN (SELECT ...)
到此:
OUTER JOIN (SELECT ...) T1