有一个数据表Id,Name,Address
1  张三   福州   
2   李四   广州
3  张五   海南
4  李五   珠海
怎么能才能显示成为。
Id,Name,Address,Id1,Name1,Address1
  1  张三   福州  2   李四   广州
  3  张五   海南   4  李五   珠海
谢谢大家拉。。

解决方案 »

  1.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (Id int,Name varchar(4),Address varchar(4))
    insert into #T
    select 1,'张三','福州' union all
    select 2,'李四','广州' union all
    select 3,'张五','海南' union all
    select 4,'李五','珠海'select a.*,b.Id as Id1, b.Name as Name1,b.Address as Address1 from #T a left join #T b on a.Id=b.Id-1 where a.Id%2=1
    /*
    Id,Name,Address,Id1,Name1,Address1
      1  张三   福州  2   李四   广州
      3  张五   海南   4  李五   珠海
    */
      

  2.   

    /*
    Id          Name        Address     Id1         Name1       Address1
    ----------- ----------- ----------- ----------- ----------- -----------
    1           张三        福州        2           李四        广州
    3           张五        海南        4           李五        珠海
    */
      

  3.   

    create table Addr
    ( id int,
      Name varchar(50),
      Address varchar(50) 
     )insert into Addr values(1,'张三','福州')
    insert into Addr values(2,'李四','广州')
    insert into Addr values(3,'张五','海南')
    insert into Addr values(4,'李五','珠海')
    select * from Addrselect a.id as id,a.Name as Name, a.Address as Address ,b.id as id1,b.name as Name1,b.Address as Address1
    from Addr a,Addr b 
    where (a.id % 2=1 and b.id % 2=0 and a.id+1=b.id)