Sql server CTE中的子查询
我想在学期结束后得到学生的身份 然后更新其表中的状态 我可以在CTE内使用子查询吗Sql server CTE中的子查询,sql-server,Sql Server,我想在学期结束后得到学生的身份 然后更新其表中的状态 我可以在CTE内使用子查询吗 ;with temp As ( select CASE WHEN Status = 0 then 'Passed' when status >0 and status < 2 then 'uncomplete' else 'Failed' end Studentstatus from ( SELECT
;with temp As
(
select CASE WHEN Status = 0 then 'Passed'
when status >0 and status < 2 then 'uncomplete'
else 'Failed' end Studentstatus
from
(
SELECT StudentID,
sum(CASE WHEN CourseStatus =1 then 1 else 0 end) Status
FROM StudentFinalResultsDetails
group by StudentID
)As t
)--the error in this line
问题是
附近的语法不正确此操作不需要子查询,可以使用CTE或子查询;您要混合这两种方法,只需执行以下操作:
with temp As
(
SELECT StudentID,
sum(CASE WHEN CourseStatus =1 then 1 else 0 end) Status
FROM StudentFinalResultsDetails
group by StudentID
) -- You have to select something after the brackets
select CASE WHEN Status = 0 then 'Passed'
when status >0 and status < 2 then 'uncomplete'
else 'Failed' end AS Studentstatus
from temp
使现代化
查询中的问题在您的问题中,您必须移动零件:
select CASE WHEN Status = 0 then 'Passed'
when status >0 and status < 2 then 'uncomplete'
else 'Failed' end AS Studentstatus`
安装在带温度的支架外侧。。。。然后在它之后选择你想要的任何东西
因为:
CTE后面必须有一个SELECT、INSERT、UPDATE或DELETE
引用部分或所有CTE列的语句。CTE也可以
在CREATE VIEW语句中指定为定义SELECT的一部分
意见陈述
在您的查询中,您没有在其后面添加任何语句。请参见您的问题是什么?您是否尝试过使用它?问题是附近的语法不正确。我需要使用CTE更新包含状态的表“StudentFinalResults”。您知道我在问题中编写的查询有什么问题吗??
select CASE WHEN Status = 0 then 'Passed'
when status >0 and status < 2 then 'uncomplete'
else 'Failed' end AS Studentstatus`