请教各位高手
现在有三张表...
按条件查询,然后把查询结果放到一张temp table
然后再用select * 输出所有的结果...可以做到一次输出两行数据么?
怎么做?
谢谢

解决方案 »

  1.   

    select top 2 *
    from temptb
      

  2.   


    with a 
    as
    (
    select *,ROW_NUMBER( ) Over(Order by 国家) RN from 水果表
    ), 
    b as
    (
    select *,ROW_NUMBER( ) Over(Order by 国家) RN2 from a Where RN%2=1
    ),
    c as
    (
    select *,ROW_NUMBER( ) Over(Order by 国家) RN2 from a Where RN%2=0
    )
    select * from c
    LEFT JOIN b ON b.RN2=C.RN2
      

  3.   

    /*
    create table ta(id int identity(1,1),国家 nvarchar(10), 水果 nvarchar(10))
    insert into ta
    select '中国','香蕉' union all
    select '美国','莲雾' union all
    select '日本','桔子' union all
    select '中国','桔子' union all
    select '美国','梨' union all
    select '日本','西瓜' union all
    select '中国','哈密瓜' */select a.国家,a.水果,b.国家,b.水果 from 
    (select id,国家,水果 from ta where id%2=1)a 
    left join
    (select id,国家,水果 from ta where id%2=0)b
    on a.id+1=b.id
    /*
    中国 香蕉 美国 莲雾
    日本 桔子 中国 桔子
    美国 梨 日本 西瓜
    中国 哈密瓜 NULL NULL*/