学生各科成绩展示

 

经典的面试题,有三张表:学生表Student, 科目表Course, 成绩表Score,要求展示学生各科成绩。

表结构:

--学生表
create table Student
(
    sid int primary key,
    name varchar(200),
    gender bit,
    age int,
)

--科目表
create table Course
(
    cid int primary key,
    name varchar(100)
)

--成绩表
create table Course
(
    cid int primary key,
    sid int,
    cid int,
    score decimal default 0
)  

 

要求按一下格式显示:

select Student.id,Student.name,
sum(case Course.name when '语文' then Score.score) as '语文',
sum(case Course.name when '数学' then Score.score) as '数学',
sum(case Course.name when '英语' then Score.score) as '英语'
from Student,Course,Score 
where Student.sid=Score .sid and Course.cid=Score.cid 
group by Student.sid

 

posted on 2017-08-17 00:11  MojoJojo  阅读(292)  评论(0)    收藏  举报

导航