• MYSQL基础子查询(子查询与IN / 比较运算符 / exists / any /all 连用)


    『1』带IN的子查询

      employee表

      

      department表

      

      SELECT num,d_id,name,age,sex,homeaddr

          FROM employee

              Where d_id in (select d_id from department);

      

    『2』带比较运算符的子查询

      scholarship表

      

      computer_stu表

      

      SELECT id,name,score

          FROM computer_stu

              WHERE score>=(select score from scholarship where level=1);

      

     

    『3』带EXISTS关键字的子查询

      使用exists关键字时,内层查询语句不返回查询的记录。而是返回一个真假值。当返回true执行,返回flase不执行

      employee & department表 见实例一

      SELECT * FROM employee 

           WHERE EXISTS

              (select d_name from department

                  where d_id=1003);

        

      SELECT * FROM employee 

           WHERE EXISTS

              (select d_name from department

                  where d_id=1004);

      

    『4』带ANY关键字的子查询

      computer_stu & scholarship表 见实例3

      SELECT * FROM computer

          WHERE score >=any (select score from scholarship);

      

    『5』带ALL关键字的子查询

      computer_stu & scholarship表同上

      SELECT * FROM computer_stu

          WHERE score >=all

            (SELECT score FROM scholarship);

      

      

      

  • 相关阅读:
    asm
    chrome-vimium在markdown插件的页面失去效果
    chrome-如何给simple world highlighter添加开关
    调整Chrome中文字体为雅黑
    最新版本的Chrome浏览器如何设置网页编码?
    访问sharepoint站点自动使用当前用户名和密码登录
    请停用以开发者模式运行的扩展
    ARM Instruction Set
    阿里前端面试
    原型链
  • 原文地址:https://www.cnblogs.com/DeepBlues/p/2997812.html
Copyright © 2020-2023  润新知