-- 16、查询和01号同学所学课程完全一样的学生信息 select group_concat(c_id) from sc group by s_id having s_id = '01'; #找出01所选修的课程 select stu.s_id,group_concat(c_id order by c_id) 选修课程 from stu left join sc on sc.s_id= stu.s_id group by stu.s_id having 选修课程 = (select group_concat(c_id order by c_id) from sc group by s_id having s_id = '01'); -- 17、查询至少有一门课与01号同学所学课程一样的学生信息 select c_id from sc where s_id='01'; select distinct stu.* from stu left join sc on sc.s_id= stu.s_id where c_id in (select c_id from sc where s_id='01');
完全匹配,例如第一题中,此时需要将零散的课程号变成一行,用group_concat()函数,行子查询
第二题中至少,此时用列子查询不用将其变为一行,,在列中进行in的匹配