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;

  • 相关阅读:
    团队项目前期冲刺-5
    团队项目前期冲刺-4
    团队项目前期冲刺-3
    团队项目前期冲刺-2
    团队计划会议
    团队项目前期冲刺-1
    大道至简阅读笔记01
    软件工程第八周总结
    梦断代码阅读笔记03
    小组团队项目的NABCD分析
  • 原文地址:https://www.cnblogs.com/wzc27229/p/11258843.html
Copyright © 2011-2022 走看看