子查询与多表查询练习

本文通过17个实例介绍了SQL中子查询和多表查询的应用,包括查询特定部门员工信息、非经理员工、经理姓名及部门、工资对比、相同工作员工、部门薪资比较、员工对比、部门详情、平均薪资比较、最低工资员工及其信息等,涵盖了复杂查询的多种场景。
摘要由CSDN通过智能技术生成

1.查询部门名称为ACCOUNTING和RESEARCH的员工信息
select *
from emp e
where e.deptno in
      (select d.deptno  
      from dept d 
      where d.dname in('ACCOUNTING','RESEARCH'));
      
2.查询不是经理的员工的信息
select *
from emp e
where e.empno not in 
      (select distinct e1.mgr 
      from emp e1 
      where e1.mgr is not null);
      
      
3.查询出所有经理的姓名及所在部门编号
select e.ename,e.deptno
from emp e
where e.empno in 
      (select distinct e1.mgr 
      from emp e1 
      where e1.mgr is not null);    
      

4.查询工资比10号部门都要低的员工信息
select *
from emp e
where e.sal<
      (select min(e1.sal) 
      from emp e1 
      where e1.deptno=10);
      
5.如何显示小于10号部门的最低工资的员工      
select e.ename,e.sal,s1.ms
from emp e,
     (select min(e1.sal) ms
      from emp e1 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值