• 配对查询关联查询


    自链接
    多表链接例题
    找出工资大于所在部门平均工资的员工姓名。
    多表链接方法 先建个表然后关联查询
    create table avg_sal_dept as select department_id, avg(salary) avg_sal from employees where department_id is not null group by department_id;
    select e.last_name, e.salary, asd.avg_sal
    from employees e, avg_sal_dept asd
    where e.department_id=asd.department_id
    and e.salary>asd.avg_sal;
    子查询方法
    select e.last_name, e.salary, asd.avg_sal
    from employees e, (select department_id, avg(salary) avg_sal from employees where department_id is not null group by department_id) asd
    where e.department_id=asd.department_id
    and e.salary>asd.avg_sal;
    ANY
    符合后面子查询的任意一个条件都可以
    in
    一个取值的列表放在里面
    例:select department_name from departments where department_id in (10,20);
    例:在Seattle工作的所有员工姓名(使用子查询和多表连接两种方式)
    子查询
    select last_name
    from employees
    where department_id in
    (select department_id from departments
    where location_id=
    (select location_id from locations where city='Seattle'));
    多表链接
    select e.last_name from employees e,departments d,locations l where e.department_id=d.department_id and d.location_id=l.location_id and l.city='Seattle';
    查找符合下列条件的员工姓名:和Abel在同一个部门,工资比Olson高
    select last_name from employees where department_id in(select department_id from employees where last_name='Abel') and salary>(select salary from employees where last_name='Olson');
    配对子查询
    select last_name, department_id, job_id
    from employees
    where (department_id, job_id)=
    (select department_id, job_id from employees where last_name='Feeney')
    and last_name != 'Feeney';

  • 相关阅读:
    css换行
    <a>标签里的<img>标签点击虚线框
    iframe子页面调用父页面元素
    快捷键
    用css绘制三角形
    解决div被embed,object覆盖问题
    一些兼容问题
    兼容padding
    记一次用html2canvas将页面内容生成海报并保存图片到本地
    PUPPETEER安装遇到 ERROR:CHROMIUM REVISION IS NOT DOWNLOADED.的解决办法
  • 原文地址:https://www.cnblogs.com/luo102154/p/7270491.html
Copyright © 2020-2023  润新知