zoukankan      html  css  js  c++  java
  • select 多表查询

    连接查询实际上是通过各个表之间共同列的关联性来查询数据的,它是关系数据库查询最主要的特征. 

    select 表1.字段名1,表2.字段名2,... 
    from 表1,表2 
    where 连接条件

    连接查询分类: 
    1.自连接查询,对同一个表进行连接操作 
    2.内连接查询,<又分为:自然连接、等值连接、不等值连接三种> 
    3.外连接查询,<又分为:左外连接、右外连接、全外连接三种> 
    4.交叉连接查询,也作无条件查询。 
    5.联合查询

    一、自连接查询: 
          
            一个表自己与自己建立连接称为自连接或自身连接。进行自连接就如同两个分开的表一样,可以把一个表的某一行与同一表中的另一行连接起来。 
    例: 
    查询选学“101”课程的成绩高于“9505201”号学生成绩的所有学生记录, 
    并按成绩从高到低排列。 
    select x.* from sclass x,sclass y 
    where x.cno=''101'' and x.degree>y.degree and y.sno=''9505201'' and y.cno=''101'' 
    order by x.degree desc 

    select  from (select degree from sclass where con='101')a, (select degree from sclass where con="101" and sno='9505201')b

    where a.degree > b.degree

    1、查询“001”课程比“002”课程成绩高的所有学生的学号;-》 查询 (同)一个学生的001课程 比 他的002 课程的成绩高。
      select a.S# from (select s#,score from SC where C#=’001′) a,(select s#,score
      from SC where C#=’002′) b
      where a.score>b.score and a.s#=b.s#;

    select  a.S# from SC a, SC b

    where a.C#='001' and b.C#='002' and a.S#=b.S# and a.score > b.score

    http://www.tuicool.com/articles/26NZry

  • 相关阅读:
    Java 8 新特性-菜鸟教程 (8) -Java 8 日期时间 API
    Java 8 新特性-菜鸟教程 (7) -Java 8 Nashorn JavaScript
    Java 8 新特性-菜鸟教程 (6) -Java 8 Optional 类
    心理相关
    matlab和Visio安装
    论文资料搜集整理(研究现状)
    调式相关
    梅花落与折杨柳
    混合高斯模型——学习笔记
    NSCT,非下采样Contourlet变换——学习笔记
  • 原文地址:https://www.cnblogs.com/ydxblog/p/5773104.html
Copyright © 2011-2022 走看看