注册 登录
编程论坛 SQL Server论坛

sql成绩表

今晚打老HU 发布于 2023-07-03 01:09, 549 次点击
TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下:
TableX
Code    Name    Age
97001    张三    22
97002    赵四    21
97003    张飞    20
97004    李五    22
TableY
Code    Class    Score
97001    数学    80
97002    计算机    59
97003    计算机    60
97004    数学    55

6.为鼓励学计算机,将年龄大于22岁的学生计算机成绩不及格的加上10分,如果加上后及格则按60分计算

求大声解答第6题
2 回复
#2
yiyanxiyin2023-07-03 10:12
select x.name,x.age,y.class, score=case when age>22 and score<60 and score>=50 then 60 when age>22 then  score+10 else score end   from tablex x, tabley y where x.code=y.code
#3
dbf永动机2023-09-27 14:32
回复 2楼 yiyanxiyin
他要求的是加了分超过60分的按照60分算,所以是不是直接按照要求替换成60分就行,没必要加10分。
1