zoukankan      html  css  js  c++  java
  • Oracle子查询和多表查询

    多表查询需要用到表的连接

    连接可以分为:(自行百度)

      交叉连接(数字逻辑的笛卡尔积,不做解释)

        等值连接

          例如:select * from t_a, t_b where t_a.xx = t_b.xx

        不等值连接

          例如:select * from t_a, t_b where t_a.sal >= t_b.sal

      内连接

        例如:select * from t_a inner join t_b on t_a.xx = t_b.xx

        内连接写法和等值连接不同,但是效果是一样的,所以随意使用一种即可。

      左外连接(左连接)

        内连接是把非空的行给连接在一起,形成一个新表。而左连接是以第一张表为基础,把符合条件的字段补充到第一张表上。

        语句:

          标准写法:select * from t_a inner left join t_b on t_a.xx = t_b.xx;

          Oracle自创:select * from t_a, t_b where t_a.xx = t_b.xx(+);

      右外连接(右连接)

        与右连接一样,方向反过来。

          select * from t_a, t_b where t_a.xx(+) = t_b.xx;

      自连接

        自身与自身相连接

        例如:select * from t_a, t_a t_a2 where t_a.xx = t_a2.yy;

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    子查询(当查询条件为不确定值时必须使用子查询)

    可以分为:

      常规子查询:

        先执行子查询,然后执行主查询,子查询参数与主查询无关。

        例如:select * from users where salary > (select avg(salary) from users)

      相关子查询:

        主查询的某些条件当作参数传入子查询,然后执行查询。

        例如:select * from users u where salary > (select avg(salary) from users where u.部门 = users.部门 order by 部门)

  • 相关阅读:
    python 函数嵌套
    python 函数对象
    python 函数参数
    python 连接MySQL报错及解决方案
    解决 No module named pip
    python 文件处理
    python
    python 元祖
    python 读取域名信息
    ubuntu 配置网卡,DNS, iptables
  • 原文地址:https://www.cnblogs.com/webyyq/p/7629280.html
Copyright © 2011-2022 走看看