Sql Server怎样用查询到的字段当条件?
题目表述不是很明确,这里用个具体事例来表达,有一个表R,里面有数学成绩MatScore、英语成绩EngScore、政治成绩PolScore、C#成绩C1Score、JAVA成绩C2Score、VC成绩C3Score、Sql Server成绩C4Score、音乐成绩MusScore、体育成绩TScore、美术成绩MScore;然后首先:
1、必修课成绩:MatScore + EngSocre + PolScore
2、专业课成绩:C1Score + C2Score + C3Score + C5Score
3、完全不重要课程成绩:MusScore + TScore + MScore
这时:要求求总成绩:1 + 2 + 3
当然可以用:MatScore + EngSocre + PolScore + C1Score + C2Score + C3Score + C5Score + MusScore + TScore + MScore 但是要求是用1、2、3来加,可是1,2,3在数据库中没有这个东西,只是为了大家好看我自己加上去的,直观一点说就是:
select MatScore + EngScore + PolScore from R where no = '1001' and classNo = '20121001' +select C1Score + C2Score + C3Score + C5Score from R where no = '1001' and classNo = '20121001' + select MusScore + TScore + MScore from R where no = '1001' and classNo = '20121001' 但是这完全不对,请问应该怎么改正?????
[最优解释]
select StudentName, (case when age=25 or age=19 then '太大或者太小'
when age between 20 and 24 then '正合适' else '随便写' end ) as type_level from R
[其他解释]
select (
select MatScore + EngScore + PolScore from R where no = '1001' and classNo = '20121001')+(
select C1Score + C2Score + C3Score + C5Score from R where no = '1001' and classNo = '20121001' )+(
select MusScore + TScore + MScore from R where no = '1001' and classNo = '20121001')
[其他解释]
select MatScore + EngSocre + PolScore 必修课成绩,
C1Score + C2Score + C3Score + C5Score 专业课成绩,
MusScore + TScore + MScore 完全不重要课成绩,
MatScore + EngSocre + PolScore +C1Score + C2Score + C3Score + C5Score+MusScore + TScore + MScore 总成绩
from R
where no = '1001' and classNo = '20121001'
[其他解释]
这里的or附近有语法错误,看来是错了,怎么修改?
[其他解释]
是这个意思:从R中取出学生的名字:如果该同学的年龄是19岁了或者是25岁了那么,太大;如果该同学的年龄是20岁到24岁那么合适。其中:该同学的年龄是19岁了或者是25岁了,不是说<19或>25是 =19或者=25
[其他解释]