基本表结构
student(id,sno,sname,sage,ssex)学生表
course(id,cno,cname,tno) 课程表
sc(id,sno,cno,score) 成绩表
teacher(id,tno,tname) 教师表
1.查询课程1的成绩比课程2的成绩高的所有学生的学号。
select a.sno
from
(SELECT sno,score FROM sc where cno=301) as a ,
(SELECT sno,score FROM sc where cno=302) as b
where a.score>b.score and a.sno=b.sno
2.查询年龄比小明大的同学的学号和姓名。
select student.sno,student.sname from
student,
(SELECT * FROM student where sname="小明") as a
where student.sage > a.sage
3.查询平均成绩大于60分的同学的学号和平均成绩。