操作 mysql练习14-16题

14 查询和“02”号的同学学习的课程完全相同的其他同学学号和姓名(同12题)

select s.s_id, s.s_name from student s join

(select s_id, count(c_id) num from score where c_id in

(select c_id from score where s_id='02') and s_id<>'02'

group by s_id

having num=(select count(c_id) from Score where s_id='02')

) r on s.s_id=r.s_id

 

参考答案

select a.s_id,a.s_name

from Student a join Score b on a.s_id=b.s_id

where c_id in (select c_id from Score where s_id='02')

and a.s_id <> '02'

group by a.s_id

having count(c_id)=(select count(c_id) from Score where s_id='02');

15 删除学习“张三”老师课的SC表记录(删除张三老师在course表中的记录,SC应该是student course吧)

delete from score

where c_id in

(select c_id from course c join teacher t on c.t_id=t.t_id where t_name='张三');

 

16 查询各科成绩最高和最低的分:以如下的形式显示:课程ID,最高分,最低分

select c_id '课程ID',max(s_score) '最高分', min(s_score) '最低分' from score group by c_id;

 

原文地址:https://www.cnblogs.com/leejunwei/p/mysql_exercises03.html