zoukankan      html  css  js  c++  java
  • Oracle 第一天

    写来自己回忆的。

    1、group by 子句

      如果select语句后跟了n个列,那么group by后面也要跟相同的n个。比如:select deptno,ename,sum(sal) from emp。

    2、where 和 having 的区别

      where不能跟组函数,having可以;

      where是先过滤后分组,而having是先分组后过滤。相比而言,where效率更高。

    3、多表查询(连接条件)

      --连接条件:表有n张,则条件至少有n-1个;

      --笛卡尔积:列数相加,行数相乘。比如一个2列*4的表与一个三列*2的表,运算后得一个5列*8的表;

      --等值连接: =

      --不等值连接: >   <

      --自连接:通过表的别名,把一个表当做多个表;

      --外连接 --按部门共计员工人数:部门化  部门名称 人数
          select d.deptno 部门号,d.dname 部门名称,count(e.empno) 人数
          from emp e,dept d
          where e.deptno(+) = d.deptno
          group by d.deptno,d.dname;
          /**
          希望:对于某些不成立的记录,仍然希望包含在最后的结果中
          左外连接:当where e.deptno = d.deptno不成立的时候,=左边的表仍然被包含
            写法:where e.deptno = d.deptno(+)
          右外连接:当where e.deptno = d.deptno不成立的时候,=右边的表仍然被包含
            写法:where e.deptno(+) = d.deptno
          */
        --自连接:通过表的别名,将同一张表视为多张表。不适合操作大表
        --查询员工信息:员工姓名  老板的姓名
        select e1.ename,(select e2.ename from emp e2 where e1.mgr = e2.empno) from emp e1;
        --层次查询:本质上为单表查询.不会产生笛卡尔积
        -- level>伪列
         select level,empno,ename,mgr from emp
         connect by prior empno = mgr
         start with empno = 7839  --从这个节点开始往下 遍历这棵树
         order by 1;
         --start with mgr is null;-- King

  • 相关阅读:
    笔记44 Hibernate快速入门(一)
    tomcat 启用https协议
    笔记43 Spring Security简介
    笔记43 Spring Web Flow——订购披萨应用详解
    笔记42 Spring Web Flow——Demo(2)
    笔记41 Spring Web Flow——Demo
    Perfect Squares
    Factorial Trailing Zeroes
    Excel Sheet Column Title
    Excel Sheet Column Number
  • 原文地址:https://www.cnblogs.com/Melody22/p/6181120.html
Copyright © 2011-2022 走看看