三张表:
student (sid,sname,sage,ssex)//学生表
course (cid,cname,tid) //课程表
sc (sid,cid,scourse)//成绩表
teacher (tid,tname)//教师表1)查出 “语文”成绩比 “数学” 成绩高的 所有学生的 学号
2) 查询 所有学科 平均成绩大于 60 的 同学的学号 和 平均成绩
3) 查询 所有学生的 学号,姓名,选课数,总成绩
4)查询 姓 “赵”的老师的人数
student (sid,sname,sage,ssex)//学生表
course (cid,cname,tid) //课程表
sc (sid,cid,scourse)//成绩表
teacher (tid,tname)//教师表1)查出 “语文”成绩比 “数学” 成绩高的 所有学生的 学号
2) 查询 所有学科 平均成绩大于 60 的 同学的学号 和 平均成绩
3) 查询 所有学生的 学号,姓名,选课数,总成绩
4)查询 姓 “赵”的老师的人数
(select a.sid from student a , course b , sc c where a.sid = c.sid and c.cid = b.cid and b.cname = '语文') m
left join
(select a.sid from student a , course b , sc c where a.sid = c.sid and c.cid = b.cid and b.cname = '数学') n
on m.sid = n.sid and m.scourse > isnull(n.scourse,0)2) 查询 所有学科 平均成绩大于 60 的 同学的学号 和 平均成绩
select m.sid , avg(n.scourse) 平均成绩 from student m, sc n where m.sid = n.sid group by m.sid having avg(n.scourse) >= 603) 查询 所有学生的 学号,姓名,选课数,总成绩
select m.sid, m.sname,count(1) 选课数 , sum(scourse) 总成绩 from student m, sc n where m.sid = n.sid group by m.sid, m.sname
4)查询 姓 “赵”的老师的人数select count(1) 人数 from teacher where tname like '赵%'
1
select student.sid from student,sc where student.sid=sc.sid and and course in
(select scourse from sc,course where sc.cid=course.cid where cname='语文')> ALL
(SELECT select scourse from sc,course where sc.cid=course.cid where cname='数学')
2
select student.sid , avg(sc.scourse) 平均成绩 from student, sc where student.sid = sc.sid group by student.sid having avg(sc.scourse) >= 60
3.
select student.sid, student.sname,count(1) 选课数 , sum(scourse) 总成绩 from student , sc where student.sid = sc.sid group by student.sid, student.sname
4
select count(1) 人数 from teacher where tname like '赵%'你没提供资料,代码没有测试,请自己去测试!