zoukankan      html  css  js  c++  java
  • 子查询

    子查询:

    嵌套在其他sql语句中的查询语句

    例: select * from table where cole1= (select cole2 from table2);

    子查询嵌套在查询内部,且必须出现在圆括号内(子查询结果必须是另一个查询的过滤条件)

     使用比较运算符的子查询: = ,>, <, !=

    any 或 some 关键词:(只要价格大于查询价格的最小值就会显示)

    例:查询书价大于图书类别编号为4的任意图书价格的所有图书信息

    select * from bookinfo where prince > any (select price from bookinfo where book_category_id = 4);

    或:

    select * from bookinfo where prince > some (select price from bookinfo where book_category_id = 4);

    ALL 关键词(只要价格大于查询价格的最大值才会显示)

    select * from bookinfo where prince > all (select price from bookinfo where book_category_id = 4);

    使用[NOT]IN的子查询

    例:查询图书信息不是“医学”的全部信息

    select * from bookinfo where book_category_id not in (select category_id from bookinfo where book= "医学" );

    使用[not]exists子查询

    select * from table where exists(子查询);

    判断子查询是否返回行,如果返回,那么exists则返回ture,否则返回fales;

  • 相关阅读:
    用C#发邮件
    .Net WinForm datagridview中无法输入中文总结
    6、linux上安装kafka
    10、linux上安装hive
    8、linux上安装hbase
    4、linux 上安装mysql
    3、hadoop的分布式安装
    12、Ambari 环境搭建
    mybtais获取插入数据的主键id
    mybatis高级映射
  • 原文地址:https://www.cnblogs.com/wzc27229/p/11258843.html
Copyright © 2011-2022 走看看