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 部门)

  • 相关阅读:
    使用zinnia制作android手写输入功能(上)编译zinnia
    Raphael实例
    正则表达式 笔记
    已知弧长和弦长求半径
    Raphael参考 翻译完毕
    在chorme中查找多余的css规则
    CSS3中Transform
    手机移动端WEB资源整合
    JS判断移动设备最佳方法 并实现跳转至手机版网页
    让IE和Firefox兼容的CSS技巧集合css hack
  • 原文地址:https://www.cnblogs.com/webyyq/p/7629280.html
Copyright © 2011-2022 走看看