查询每个部门最新入职的那位员工
创建表与数据准备
一个问题既可以使用连表查询也可以使用子查询,推荐使用连表查询,因为连表查询的效率高。
练习题
https://www.cnblogs.com/Eva-J/articles/9688383.html
8、查询课程编号“2”的成绩比课程编号“1”课程低的所有同学的学号、姓名;
9、查询“生物”课程比“物理”课程成绩高的所有学生的学号;
先获取生物课和物理课cid
select cid from course where cname=‘生物’
select cid from course where cname='物理‘
找到学物理的人
select student_id as sid2 ,num num2 from score where course_id=(select cid from course where cname='物理‘)
找到学生物的人
select student_id as sid1 ,num num1 from score where course_id=(select cid from course where cname='生物‘);
select *from (select student_id as sid2 ,num num2 from score where course_id=(select cid from course where cname='物理‘) )as t1
inner join
(select student_id as sid1 ,num num1 from score where course_id=(select cid from course where cname='生物‘)) as t2 on t1.sid1=t2.sid2 where t1.num1>t2.num2;
15、查询学过“李平老师”所教的所有课的同学的学号、姓名;
怎么找所有的?分组