zoukankan      html  css  js  c++  java
  • 数据库_CRUD操作之读取数据之高级读取

    高级读取

    1.连接查询

    select * from info,nation

    形成笛卡尔积

    select * from info,nation where info.nation=nation.code

    select Info.code,Info.name,Info.sex,Nation.name as '民族',Info.birthday from Info,Nation where Info.nation=Nation.code

    select * from Info join Nation on Info.nation=Nation.code

    2.联合查询
    select code,name from Info
    union
    select code,name from Nation

    3.子查询
    子查询查询的结果作为父查询的条件

    (1)无关子查询:子查询执行的时候和父查询没有关系
    查民族为'汉族'的所有学生信息
    select * from Info where nation=(select code from nation where name='汉族')

    查询生产厂商为'一汽大众'的所有汽车信息
    select * from car where brand=()
    select brand_code from brand where prod_code=()
    select prod_code from productor where prod_name='一汽大众'


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

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

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

    select * from car where oil<(该系列平均油耗)
    select avg(oil) from car where brand =(该系列)

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

  • 相关阅读:
    ps 玻璃效果
    svn 官方下载
    svn
    c# form 无标题
    app Inventor google 拖放手机代码块
    paas
    java 延迟
    c# 执行 cmd
    c # xml操作 (无法将类型为“System.Xml.XmlComment”的对象强制转换为类型“System.Xml.XmlElement”)
    eclipse 安装插件 link方式
  • 原文地址:https://www.cnblogs.com/ysdong/p/5970417.html
Copyright © 2011-2022 走看看