declare @t table(id int primary key,coll decimal (10,2))
insert @t select 1,26.21
union all select 2,4.21union all select 3,76.55
union all select 4,58.02
union all select 10,53.02union all select 11,66.35
union all select 8,52.10
union all select 9,12.25应该很简单,可我想半天没想出来   就是怎么选出中间那部分数据

解决方案 »

  1.   

    select *
    from @t
    where id in (3, 4, 10)
      

  2.   

    表有 两列 第一列是id  id是唯一但不连续的 也没有大小顺序现在我要取出 这个表的 第3行到第5行的数据
      

  3.   

    to :zxkid  如果我要取中间的100个行 那要自己写100个id了 晕 这法子不行
      

  4.   

    declare @t table(id int primary key,coll decimal (10,2))
    insert @t select 1,26.21
    union all select 2,4.21union all select 3,76.55
    union all select 4,58.02
    union all select 10,53.02union all select 11,66.35
    union all select 8,52.10
    union all select 9,12.25seelct top 3 * from @t
    where id not in (
    select top 2 id from @t 
    )
      

  5.   

    id 即然是primary key,insert时已经排序了
    你这个不加其它字段没办法的
      

  6.   

    to :Yang_(扬帆破浪)  top是按照id大小 按照你的语句 结果是
    3 76.55
    4 58.02
    8 52.10
      

  7.   

    SELECT TOP * FROM @t WHERE id NOT IN(SELECT TOP 2 id FROM @t)
      

  8.   

    sql 里有没有 取行的函数啊? 返回指定的行
      

  9.   

    declare @t table(id int primary key,coll decimal (10,2))
    insert @t select 1,26.21
    union all select 2,4.21union all select 3,76.55
    union all select 4,58.02
    union all select 10,53.02union all select 11,66.35
    union all select 8,52.10
    union all select 9,12.25DECLARE @COUNT INT
    DECLARE @A INT
    DECLARE @B INT
    DECLARE @C INTSELECT @COUNT = COUNT(*) FROM @t
    SELECT @COUNT 
    SELECT @A  = @COUNT/3   --- 上IF (@COUNT%3 = 1)
      BEGIN
           SELECT @C = @A +1
           SELECT @B =  @A
       END
    ELSE 
     IF (@COUNT%3 = 2)
              BEGIN
    SELECT @B  = @A+1
    SELECT @C  = @A+1
    END
    ELSE  
    IF (@COUNT%3 =  0)
    BEGIN
    SELECT @B =  @A
    SELECT @C = @A
    ENDSELECT @A ---- 上
    SELECT @B ---- 中
    SELECT @C -----下 select top @B * from  @t where id not in ( select top @A id   from @t)
      

  10.   

    把它总记录数 分成3部分例子:总记录数 第一部分  第中部分   第三部分 
            8      2,         3,          3
            10     3,         3,          4
           100     33,        33,        34SELECT @A ----第一部分 
    SELECT @B ---- 第中部分 
    SELECT @C -----第三部分