select *
from (
    select row_number()over(order by t.hid) 索引,*
    from (select top 10 * from hotel)t
)tt
where 索引>5
我想把上面的查询结果再和另外一张表做一次连接应该怎么做?

解决方案 »

  1.   


    --如果是SQL SERVER 2000的话--嵌套一下select * from 
    (
    select *
    from (
        select row_number()over(order by t.hid) 索引,*
        from (select top 10 * from hotel)t
    )tt
    where 索引>5
    ) a left join 另外的表 b on a.id=b.id--如果是SQL SERVER 2005+的话--用with 表达式;with a as
    (
    select *
    from (
        select row_number()over(order by t.hid) 索引,*
        from (select top 10 * from hotel)t
    )tt
    where 索引>5
    )
    select * from a left join 另外的表 b on a.id=b.id
      

  2.   

    --根据你的情况,最好直接连查即可。select *
    from (
        select row_number()over(order by t.hid) 索引,*
        from (select top 10 * from hotel)t
    ) tt left join 另外一张表 b on tt.字段=b.字段
    where tt.索引>5