• 高级查询


    高级查询

    1.连接查询:

    select*from info


    第一个形式,
    select* from info, nation #形成一个笛卡尔积 适合数据量小的时候使用
    select*from info, nation where  [info.nation]info表中的nation列=nation.code

    第二个形式

    select* from info [join]连接 nation on info nation = nation.code


    2.联合查询 ,对结果集行的扩展
     select code , name from info
    union  联合关键字
    selerct code , name from nation

    3.子查询(里查询)

    父查询(外查询)
    子查询的结果作为父查询的条件

    (1)无关字查询
    子查询在执行的时候和父查询没有关系,子查询可以单独执行

    a.查询民族为汉族的所有人员信息:
    父查询:select * from info where nation =()
    子查询:select code from nation where name ='汉族'
    select * from info where nation =(select code from nation where name ='汉族')

    b。查询系列名为宝马5系的所有汽车信息
    select * from car where brand = ( select brand _code from brand where brand _name = '宝马5系')

    (2)相关子查询
    子查询在查询的时候和父查询有关系,不能单独执行
    a.查询汽车表中油耗小于该系列平均油耗的所有汽车信息:
     父查询:select *from car where oil<(该系列平均油耗)
     子查询:select avg(oil) from car where brand = 该系列
     select *from car as ‘a’ where oil<(select avg(oil) from car as 'b' where b brand = a brand) 给表单加别名用as ,as后面

    直接写 别名

  • 相关阅读:
    安装go语言开发环境
    【Graph】399. Evaluate Division(Medium)
    【Divide and Conquer】53.Maximum Subarray(easy)
    int数组交并差集
    Git强制覆盖本地文件
    Git手动合并
    [转]关于BETA、RC、ALPHA、Release、GA等版本号的意义
    [置顶] java处理office文档与pdf文件(二)
    [置顶] 左联接数据不统一问题
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/gdbaby/p/6130281.html
Copyright © 2020-2023  润新知