--三
use jxgl_3rd;
--1 查询选修课程8105且成绩在80到90之间的所有记录
select *
from SC
where Grade between 80 and 90
--2 查询成绩为79 89 99的记录
select *
from SC
where Grade in('79','89','99');
--3.查询9803班的学生人数
select COUNT(*)
from Student
where Sclass='9803';
--4.查询至少有20名学生选修的 并且课程号以8开头的课程
---的平均成绩
select Cno
from SC
where Cno like '8%'
group by Cno having (COUNT(*)>=20)
--5.查询 最低分大于80 最高分小鱼95 的sno与平均分
select SC.Sno,AVG(Grade) --*
from SC,Student
where SC.Sno=Student.Sno --order by SC.Sno
group by SC.Sno
having (MIN(SC.Grade)>80 and MAX(SC.Grade)<95)
--6 查询9803班学生所选各课程的课程号及其平均成绩
select SC.Cno,AVG(Grade)
from SC,Student
where Student.Sclass='9803' and SC.Sno=Student.Sno
group by SC.Cno
--7.查询选修8105课程的成绩高于980302号同学的所有同学的记录
select *
from Student
where Sno in(
select Sno
from SC
where SC.Cno='8105'and SC.Grade>(
select Grade from SC where Sno='980302' and Cno='8105')
)
--8.查询 与学号为980103的同学同岁的所有学生的
--sno sname 和age
select Sno,Sname,Sage
from Student
where Sno!='980103' and Sage=(
select Sage from Student where Sno='980103'
)
--9 查询钱军教师任课的课程号 以及选修其课程的学生的学号和
--成绩
select Cno,Sno from SC
where Cno in(
select Cno from Teacher,Course
where Tname='钱军' and Teacher.Tno=Course.Tno
)
--10 查询选修某课程的学生人数多于20人的教师姓名
select Tname from Teacher,Course where Teacher.Tno=Course.Tno and Cno
in
(
select Cno from SC group by Cno having COUNT(*)>20
)
--11 查询 选修编号为8105课程且成绩至少高于其选修编号为8245 课程的同学
-- 的sno及8105 课程成绩,并按照成绩从高到低依次排列
select Sno from Student where
use jxgl_3rd;
--1 查询选修课程8105且成绩在80到90之间的所有记录
select *
from SC
where Grade between 80 and 90
--2 查询成绩为79 89 99的记录
select *
from SC
where Grade in('79','89','99');
--3.查询9803班的学生人数
select COUNT(*)
from Student
where Sclass='9803';
--4.查询至少有20名学生选修的 并且课程号以8开头的课程
---的平均成绩
select Cno
from SC
where Cno like '8%'
group by Cno having (COUNT(*)>=20)
--5.查询 最低分大于80 最高分小鱼95 的sno与平均分
select SC.Sno,AVG(Grade) --*
from SC,Student
where SC.Sno=Student.Sno --order by SC.Sno
group by SC.Sno
having (MIN(SC.Grade)>80 and MAX(SC.Grade)<95)
--6 查询9803班学生所选各课程的课程号及其平均成绩
select SC.Cno,AVG(Grade)
from SC,Student
where Student.Sclass='9803' and SC.Sno=Student.Sno
group by SC.Cno
--7.查询选修8105课程的成绩高于980302号同学的所有同学的记录
select *
from Student
where Sno in(
select Sno
from SC
where SC.Cno='8105'and SC.Grade>(
select Grade from SC where Sno='980302' and Cno='8105')
)
--8.查询 与学号为980103的同学同岁的所有学生的
--sno sname 和age
select Sno,Sname,Sage
from Student
where Sno!='980103' and Sage=(
select Sage from Student where Sno='980103'
)
--9 查询钱军教师任课的课程号 以及选修其课程的学生的学号和
--成绩
select Cno,Sno from SC
where Cno in(
select Cno from Teacher,Course
where Tname='钱军' and Teacher.Tno=Course.Tno
)
--10 查询选修某课程的学生人数多于20人的教师姓名
select Tname from Teacher,Course where Teacher.Tno=Course.Tno and Cno
in
(
select Cno from SC group by Cno having COUNT(*)>20
)
--11 查询 选修编号为8105课程且成绩至少高于其选修编号为8245 课程的同学
-- 的sno及8105 课程成绩,并按照成绩从高到低依次排列
select Sno from Student where