• 高级查询


    高级查询
    1.链接查询 对列的扩展
    (1)逗号  ,  where
    select * from info,nation  形成笛卡尔积  表与表链接在from后面,逗号分开
    select * from info,nation where info.nation=nation.code  后面添加条件
    select info.code,info.name,info.sex,info.name,info.birthday from info,nation where info.nation=nation.code     筛选出自己要的项目
    (2)关键字join   on
    select * from info join nation
    select * from info join nation on info.nation=nation.code  join和on是一对
    2.联合查询 对行的扩展
    select code,name from info
    union
    select code,name from nation   联合查询注意列的结构,列名必须相同
    3.子查询:
    (1)无关子查询
    外层查询(里层查询)
    子查询的结果,当作复父查询的条件
    例子:查找汉族所有人
    子查询:select code from nation where name='汉族'
    父查询:select*from info nation=''
    结合:select*from info nation=(select code from nation where name='汉族')
    (2)相关子查询
    例子:查询汽车表中油耗低于该系列平均油耗的所有车辆信息
    父查询: select * from car where dil<(该系平均油耗)
    子查询: select avg(oil) from car where brand='某个系列'
    select * from car a where a.oil<(select svg(oil) from car b where b.brand=a.brand) 添加虚拟表名,只用在相关子查询中

  • 相关阅读:
    变量
    注释 & 缩进
    【oracle】生成AWR报告
    【Linux】awk指令
    rhel7.0替换centos yum源
    如何在乌班图上配置java开发环境
    如何在乌版图系统添加拼音输入法!
    如何让虚拟机中乌版图系统变大?
    如何重置虚拟机的乌版图系统的密码?
    虚拟机三种网络模式配置
  • 原文地址:https://www.cnblogs.com/panyiquan/p/5540236.html
Copyright © 2020-2023  润新知