zoukankan      html  css  js  c++  java
  • 一道sql面试题的解答

    题目:

      写出一条Sql语句:

        取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键,  注意:ID可能不是连续的。)

    解答(已测试):

      1、假设ID是连续的:

        select top 10 * from A where ID not in (select top 30 ID from A)

      或

        select  *  from A where ID between 31 and 40

      2、假设ID是不连续的:

         select top 40 * from A except select top 30 * from A

      或

        select top 10 * from A where ID > (select max(ID) from A where ID in (select top 30 ID from A))

         或

        select top 10 * from A where ID not in (select top 30 ID from A) 

  • 相关阅读:
    python的元类
    中国的互联网:草根与精英
    PEP8中文翻译
    一些重要的算法
    tornado模板语法
    C#l类与对象
    sql_ 存储过程
    SQL_触发器
    SQL_事务处理
    C#_方法
  • 原文地址:https://www.cnblogs.com/puresoul/p/1764249.html
Copyright © 2011-2022 走看看