zoukankan      html  css  js  c++  java
  • 高级查询笔记

    高级查询
     
    1.连接查询(对列的扩展)
     第一种形式:
    select*from info,nation #笛卡尔积
    
    select*from info,nation where info.nation=nation.code #加上筛选条件
    
    select info.code,info.name,sex, nation.name,birthday from info,nation where info.nation=nation.code#查询指定列
    
    select Info.Code as'代号',Info.Name '姓名',Sex as '性别',Nation.Name as '民族',Birthday as '生日'from info,nation where info.nation=nation.Code#换表头
     第二种形式:
    select*from info join nation #joinl连接
    
    select*from info join nation  on info.nation=nation.code#join on关键字
    
    2.联合查询(对行的扩展)
    
    select *from info where nation='noo2'
    union
    
    select *from info where code='poo2'
    
    3.子查询(无关子查询)
    
    在一个sql语句中,至少有两个查询,其中一个a查询的结果作为另一个B的查询条件,a成为里层查询或者子查询,b成为外层查询或父查询。
    查询民族为“汉族”的人员信息:
    
    select *from Info where Nation=(select code from Nation where Name='汉族')
    
    查询民族为“汉族”或者“回族”的人员信息
    
    select*from Info where Nation in (select Code from Nation where Name='汉族'or Name='回族')
    
    
    
    4.子查询(相关子查询)
    
    
    查询同一系列的 油耗要比平均油耗低的汽车信息
    
    
     子查询:select avg(Oil)from Car where Brand=''
    
    父查询:select*from Car where Oil<平均油耗
    
    select*from Car a where a. Oil<(select avg(b.oil) from  Car b where b. Brand=a.Brand)
    
    
     
  • 相关阅读:
    纯awk传参和awk脚本传参
    【转】MySQL 备份和恢复(MyISAM 和 Innodb)
    【z】多线程Java Socket编程示例
    Java,Tomcat,Mysql乱码总结
    mysql备份与同步shell脚本
    【转】Velocity用户手册中文版(学习修改版)
    wml新学的标签
    【原】小心log4j的多进程写入
    【z】Webservice 的设计和模式
    【z】linux面试题参考答案
  • 原文地址:https://www.cnblogs.com/crazy-zw/p/5290005.html
Copyright © 2011-2022 走看看