SQL基本查询_子查询(实验四)

时间:2024-09-29 13:08:02

SQL基本查询_子查询(实验四)

SQL基本查询_子查询(实验四)

1、查询所有员工中薪水低于“孙军”的员工姓名和薪水;
2、查询与部门编号为“01”的岗位相同的员工姓名、岗位、薪水及部门号;
3、查询与“王伟”岗位相同的所有员工信息,显示姓名、岗位、薪水及部门号;
4、查询部门位置在“7号楼”的所有员工信息,显示姓名、薪水及部门编号;
5、查询薪水高于部门编号为“01”的所有员工薪水的员工姓名、工资和部门编号;

1.
select ename 姓名,sal 薪水
from emp
where sal<all(select sal from emp where ename = '孙军')
2.
select ename,job,sal,deptno
from emp
where job in (select distinct job from emp where deptno = '01')
3.
select ename,job,sal,deptno
from emp t
where job in (select distinct job from emp where ename = '王伟' )
4.
select ename,sal,deptno
from emp
where exists(select deptno from dept where loc = '7号楼'and emp.deptno = 

deptno)

5.
select ename,sal,deptno
from emp
where sal>all(select sal from dept where deptno = '01')

SQL基本查询_子查询(实验四)

1、查询所有高于“06100101”同学“0002”号课成绩的其它选课成绩,显示其学号、课程号及成绩。
2、查询每个学生高于其选修的“0002”号课成绩的其它选课成绩,显示其学号、姓名、课程号及成绩。
3、查询“数据库系统原理”课程的考试情况;
4、查询选修“0001”号课的学生学号和姓名。

1.
select scc.sno, scc.cno,grade
from sc scc
where grade > all(select grade from scc where scc.cno = '002' and scc.sno = '0610010' )
2.

select scc.sno,sname,scc.cno,grade
from sc scc,student t
where grade > any(select grade from scc,t where t.sno = scc.sno and scc.cno = '0002')

4.
select sno,sname
from student
where sno = all(select scc.sno from sc scc where cno = '0001')