应如何写SQL语句
a表
select name pay from a  
aa 1
bb 4
aa 3
cc 6
nn 9
gg 5
查询第三行和第四行(或指定的其他行),结果为
aa 3
cc 6

解决方案 »

  1.   

    select tid=identity(int,1,1),* into # from a
    select * from # where tid=3
    drop table # 
      

  2.   

    查询时加个自增长的列id,然后用id in(3,4)行不行?
      

  3.   

    select tid=identity(int,1,1),name,pay into # from 表a
    select * from # where tid=3 --6或其他
    drop table #
      

  4.   

    谢谢各位大侠的热心帮忙,但我想要的是一条SQL语句来实现,也就是不用加其他列或表来实现.不知道是否能实现得了
      

  5.   


    --> (让你望见影子的墙)生成测试数据,时间:2008-12-13
     
    if not object_id('tb') is null
    drop table tb
    Go
    Create table tb([name] nvarchar(2),[tid] int)
    Insert tb
    select N'aa',1 union all
    select N'bb',4 union all
    select N'aa',3 union all
    select N'cc',6 union all
    select N'nn',9 union all
    select N'gg',5
    Go
    Select * from tbselect tid=identity(int,1,1),* into # from aselect name ,tid from # where id between 3 and 4
      

  6.   


    declare @a table (sn nvarchar(10),id int)
    insert into @a select 'aa',1
         union all select 'bb',4
         union all select 'aa',3
         union all select 'cc',6
         union all select 'nn',9
         union all select 'gg',5
    select sn,id from (
    select row_number()over(order by sn) as 序号 ,* from @a
    ) a where 序号 in(2,4)
    aa 3
    cc 6