基本SQL语句,都进来看看

来源:百度知道 编辑:UC知道 时间:2024/05/18 19:20:52
常见的数据库:stu
三个表:student(学生表),course(课程表),sc(成绩表)
其中student字段:sno(学号),sname(姓名),age(年龄),department(系)
course:cno(课程号),cname(课程名),ccredit(学分)
sc:sno(学号),cno(课程号),grade(成绩)

现在要求以下列方式显示数据:
学号 姓名 数学 语文 英语

其中课程表里还包括其他多门课程:请用尽量简短的SQL语句实现

select a.sno,
a.sname,
(select max(grade)
from sc
where sno = a.sno
and cno in (select cno from course where cname = '数学')),
(select max(grade)
from sc
where sno = a.sno
and cno in (select cno from course where cname = '语文')),
(select max(grade)
from sc
where sno = a.sno
and cno in (select cno from course where cname = '英语'))
from student a

注意此sql不支持Access 数据库

select s.sno,
s.sname,
(select from c.grade
from c, sc
where sc.con = c.con
and c.cname = '数学'
and sc.sno = s.sno
and c.cno = sc.cno) 数学,
(select from c.grade
from c, sc
where sc.con = c.con
an