pta mysql训练题集(321-340)

10-321 查询“谭浩强”教师任课的课程号,选修其课程的学生的学号和成绩,结果中包括该老师没有被选修的课程

select b.cno cno,c.sno sno,c.score
from teachers as a
left join teaching as b on b.tno=a.tno
left join sc as c on b.cno=c.cno 
where a.tname='谭浩强'

10-322 列出所有学生的选课情况(包括学号,姓名,课号,成绩),结果中包括没有选课的学生

select students.sno,sname,cno,score
from students
left join sc on students.sno = sc.sno;

10-323 查询没有选课的学生学号和姓名

select sno,sname
from students
where sno not in (select sno from sc)

10-324 查询信息学院学生所选修的课程号和成绩

select cno,score
from sc
where sno in
(
select sno
from students
where sdept = '信息学院'
) 

10-325 查询与“陆毅”同一个系的同学姓名

select sname
from students
where sdept = (select sdept from students where sname = '陆毅') and sname != '陆毅'

10-326 查询“19信管2”班的学生所选修的课程号

select cno
from students,sc
where students.sno = sc.sno and class='19信管2';

10-327 查询“陈晓东”同学所选课程的课号及成绩

select cno,score
from students
inner join sc on students.sno = sc.sno
where sname = '陈晓东'

10-328 查询出生日期大于所有女同学出生日期的男同学的姓名及系别

select sname,sdept
from students
where ssex = '男' and bday > (select max(bday) from students where ssex = '女')

10-329 查询选修了课号为“0000034”的学生学号和姓名

select sc.sno,sname
from students,sc
where students.sno = sc.sno and cno = '0000034';

10-330 查询“0000008”号课程不及格的学生信息

select *
from students
where sno in (select sno from sc where score < 60 and cno = '0000008');

10-331 查询李小鹏同学所选课程名称

select cname
from course
where cno in
(
    select cno
    from sc
    where sno = (select sno from students where sname = '李小鹏')
);

10-332 查询“王珊”老师所授课程的课程名称

select cname 
from course
where cno in 
(
    select cno
    from teaching
    where tno = (select tno from teachers where tname = '王珊')
);

10-333 向Students表中插入一条记录

insert into students 
values
("2002031","胡静","20财管1","女","2000-3-21","黑龙江齐齐哈尔","230200200003210023","经管学院","6583891");

10-334 插入学号为“2003024”、姓名为“李光”的学生信息

insert into students
(sno,sname)
values
('2003024','李光');

10-335 将学号为“1911201”的学生系别改为“经管学院”,班级改为“19经管1”

update students
set sdept = '经管学院',class = '19经管1'
where sno = '1911201';

10-336 将学号为“1911203”的学生的联系电话改为“590987”

update students
set phone = 590987 where sno = 1911203

10-337 把选修了“平板撑”课程而成绩不及格的学生的成绩全改为空值(NULL)

update sc
set score = null
where score < 60 and cno = (select cno from course where cname = '平板撑')

10-338 删除学号为“1911102”的学生记录

delete from students
where sno = 1911102

10-339 删除“经管学院”所有学生的选课记录

delete from sc
where sno in (
    select sno
    from students
    where sdept = '经管学院'
)

10-340 删除SC表中尚无成绩的选课记录

delete from sc
where score is null;

你可能感兴趣的:(狂刷MYSQL,mysql)