zoukankan      html  css  js  c++  java
  • 高级查询---嵌套and分页

    高级嵌套语句:

    子查询: 

    语句:

    select * from 表名

    where 列名=

    子查询语句

    注意:子查询语句必须放在小括号呢 可以使用< >=等运算符号,sql server 执行时 会优先先进行子查询 

    因为子查询作为where条件的一部分 所以 可以和 update insert delete 一起使用

    in 和 not in子查询:

    当使用< > =等运算符号进行子查询时 要求 返回值不能 大于1,所以 int 和 not in 的子查询就避开了这一限制 

    举个列子  要查询没有学员参加oop考试的学员名字

    --查询没有参加oop的学员名字
    select studentname
    from student
    where StudentNo not in
    (
    select StudentNo
    from Result
    where ExamDate=
    (
    select MAX(ExamDate)from Result
    where SubjectId=
    (
    select SubjectId from Subject
    where SubjectName='oop'
    )
    )

    可以很 明显的看出 所谓 的 int  not int子查询 只是把where条件的运算符号 改为了 in 或 not int 。

    分页查询:

    分页查询分为两种:

    1用双 top 和 双 order by 进行分页 

    select top 4 *from student
    where studentName not in
    (
    select top 4 StudentName from Student
    order by StudentName
    )
    order by StudentName

    重点:外层先要确定好要显示几行数据,内层要选择从几到几进行分页

    2. --在表中 构建一列 并按序号排列(别名列)用别名列进行分页

    select * from
    (
    select *,ROW_NUMBER() over (order by studentno) as Myid
    from Student
    )
    as temp
    where Myid between 3 and 4

  • 相关阅读:
    大道至简读后感(第二章)
    大道至简读后感
    将课程中的所有动手动脑的问题以及课后实验性的问题,整理成一篇文档
    python之基础
    python之面向对象
    python之网络编程
    python之函数
    Managing SharePoint 2010 Farm Solutions with Windows PowerShell
    Oracle RMAN vs. Export?
    转帖在oracle中自动大批量生成测试数据
  • 原文地址:https://www.cnblogs.com/hero96/p/5259550.html
Copyright © 2011-2022 走看看