zoukankan      html  css  js  c++  java
  • 20170731上课笔记

    自查询

    select e.employees_id,m.employees_id||':'||m.last_name from employees e,employees m where e.employees_id=m.manager_id

    子查询

    select m.last_name,m.salary,round(e.c,2) avgsalary,d.department_name/*姓名,工资,平均工资,部门*/

    from employees m,/*基本表*/

    (select department_id,avg(salary) c from employees  group by department_id) e,/*部门工资平均值*/

    departments d/*部门表*/

    where e.department_id=m.department_id(+)  /*基本表和平均值表关联 */      

    and m.department_id=d.department_id(+)/*部门表和基本表关联*/

    and m.salary>e.c /*人员工资大于部门平均工资*/

     

     

    rownum

    in  包含在里边意思

    not in

    any或者关键字意思 where 字段<any selecy XXX from ..where..);

    all and关键字意思where 字段<any selecy XXX from ..where..);同时小于

    > < >= <= <>

    select * from XX where exists(子查询) exists只需要判断是否有子查询里的数据

    in not in当条件返回值为空时,not in语句将报错 in正常

    而当existsnot exists时不需处理null

    多表连接查询效率低于子查询

    set autotrace on

    //查看任务计划可查看其语句消耗占用

    rownum只能用<= //当有排序时,会先执行rownum再排序,因此排序将不生效,所以需要用子查询嵌套进行排序

    select * from (select last_name, salary from employees order by salary desc) where rownum<=3

    分页查询:

    SQL> select * from

    (select * from

    (select * from

    (select last_name, salary from employees order by salary desc)

    where rownum<=6)

    order by salary)

    where rownum<=3

    order by salary desc;

    SQL> select last_name, salary

     from (select rownum row_num, v1.*

                 from

                   (select last_name, salary from employees order by salary desc) v1

             ) v2

     where row_num between 4 and 6;

     select last_name, salary

     from (select rownum row_num, v1.*

                 from

                   (select last_name, salary from employees order by salary desc) v1

                 where rownum<=6

             ) v2

     where row_num >= 4;

  • 相关阅读:
    yii2.0数据库查询修改等方法
    yii2.0里自己写的源码上传图片
    解决yii2.0里url重写引用js路径问题(@web/的用法)
    yii2.0中解决post的400错误
    yii2.0用gii自动补全代码做的简单增删改查,以及图片上传和展示
    yii2.0中url重写实现方法
    (转)openssl 命令: openssl req 命令详解
    Nodejs搭建音视频通信-信令服务器 总结
    【转】阿里架构总监一次讲透中台架构,13页PPT精华详解
    (转)SSL工作原理
  • 原文地址:https://www.cnblogs.com/guoxf/p/7266606.html
Copyright © 2011-2022 走看看