• 子查询和查询表达式


      这个比较实用,可能用的比较少,但是对于比较的sql查询来说,可以省去很多麻烦,直接使用子查询。

      

        子查询是一个查询内的查询。子查询的结果被DBMS使用来决定包含这个子查询的高级查询的结果。在子查询的最简单的形式中,子查询呈现在一条SQL语句的WHERE或HAVING字句内。

        select field from table where field2 > (select field from table2 where ...)

        

        子查询搜索条件(>、<、==、<=、>=):

          子查询比较测试:

            select field from table where field >= (select field from table2 where ...)

          组成员测试(IN):

            select field from table where field (NOT)IN (select field from table2 where field1 > field2)

    存在测试(EXISTS):

        select field from table where EXISTS (select ...)

        select field from table1 where field = (select field from table2 where field1 = value) and NOT EXISTS (select * from table3 where ...)

    限定测试(ANY 和 ALL)

        IN测试的子查询版检查数据是否等于子查询结果字段中的某些值。SQL提供了两个限定测试ANY 和 ALL,把这种概念扩展到其他比较运算符。

        ANY测试:

            ANY测试和6个SQL比较运算符一起使用,用于把一个测试值和由子查询产生的一个字段的数据值相比较。要执行这个测试,SQL使用特定的比较运算符来把测试值和字段中的每个数据值进行比较,如果有一个比较产生TRUE,那么ANY测试返回TRUE结果。

            select field from table where field < ANY (select field from table2 where field = value)

            select field from table where field < > ANY (select field from table2)

        ALL测试:

            像ANY测试一样,ALL测试和6中SQL比较运算符之一一起使用,可用于把单个测试值和由子查询产生的数据字段相比较。要执行这项测试,SQL使用特定的比较运算符来把测试值和字段中的每个数据值进行比较。如果所有的比较都生成TRUE结果,那么ALL测试返回TRUE值。

            select field from table where field < ANY (select field from table2 where field = value)

            ALL测试总能转换成对应的EXISTS测试。

  • 相关阅读:
    TDH-hbase shell 常用命令
    WebService之基于REST机制的实现实例(Java版)
    大牛地址
    Solr的SolrCloud与Master-slave主从模式对比
    solr亿万级索引优化实践-自动生成UUID
    Solr查询中涉及到的Cache使用及相关的实现【转】
    05-spectral 图机器学习之谱分解
    03-motifs 图机器学习之motif和结构角色
    04-communities 图机器学习之社区
    02-gnp-smallworld 图机器学习之最小世界
  • 原文地址:https://www.cnblogs.com/fanchangfa/p/2633821.html
Copyright © 2020-2023  润新知