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;

  • 相关阅读:
    24. Swap Nodes in Pairs
    2. Add Two Numbers
    【设计模式】结构型模式
    【设计模式】创建型模式
    【设计模式】初识
    【自考总结】走过的弯路,都是你成长的旅途
    【VMware vSphere】再谈VMware vSphere
    评估网站性能的专业术语
    C/S与B/S之辩
    【VMware vSphere】Veeam备份
  • 原文地址:https://www.cnblogs.com/wzc27229/p/11258843.html
Copyright © 2011-2022 走看看