• 高级查询


    连接查询:

    select * from 表名1,表名2#形成笛卡尔积

    select * from 表名1,表名2 where 表名1.列名=表名2.列名  //  select  表名1.列名, 表名1.列名1,表名2.列名 as'民族' from 表名1,表名 where 表名1.列名=表名2.列名

    select * from 表名1 jion 表名2 on 表名1.列名=表名2.列名  

    联合查询:

    select 列名1,列名2 from 表名1 union select 列名1,列名2 from 表名2

    子查询:子查询查询结果作为父查询的条件

             无关子查询:子查询执行的时候和父查询无关系

            select * from 表名 where 列名=(select 列名 from 表名 where 列名=‘民族’)

              举例:查民族为'汉族'的所有学生信息

              select * from Info where nation=(select code from nation where name='汉族')

           select * from 表名 where 列名 in(select 列名 from 表名 where 列名=(select 列名 from 表名 where 列名=‘’))

            举例: 查询生产厂商为'一汽大众'的所有汽车信息

            select * from car where brand in(select brand_code from brand where prod_code=(select prod_code from productor where prod_name='一汽大众'))

      

             相关子查询:子查询在执行的时候需要用到父查询的内容

              select * from 表名 where 列名=()

              select avg(列名) from 表名 where 列名 =()

                 举例:查询汽车表中,汽车油耗小于该系列平均油耗的所有汽车信息

                 select * from car a where oil<(select avg(oil) from car b where b.brand =a.brand)

            

            

  • 相关阅读:
    初识 vue
    Spring boot 整合 Swagger
    Swagger 注解
    初识 Swagger
    初识 mycat
    SpringBoot中的国际化
    为什么博客园用户体验这么差?
    Numpy常用方法及应用总汇
    嵌入式开发10种常见数字滤波算法
    .gitignore使用
  • 原文地址:https://www.cnblogs.com/gaojunshan/p/5969905.html
Copyright © 2020-2023  润新知