SQL student score

来源:百度知道 编辑:UC知道 时间:2024/06/25 17:53:58
按要求写出SQL
student表
id name
21 张三
22 李四
23 王五
score表
id student_id score
11 21 90
12 22 80
要求查询结果如下:
name score
张三 90
李四 80
王五 0
假如缺考记为0分

select name,score=case
when score is null then 0
else score
from student left jion score on student.id=score.student_id

SQL2005测试结果:
select
a.name,isnull(b.score,0) as 'score'
from
student a
left join
score b
on a.id=b.student_id

最佳方式:
select s.name as '学生姓名',
考试分数 = case
when sc.score is null then 0
else sc.score
end
from student as s left join score as sc on(sc.student_id =s.id)

我回答得最快哈
有错就赶快说 我马上纠正