create table test(name varchar(10),sex bit)
insert into test values('a',0)
insert into test values('b',0)
insert into test values('c',1)
insert into test values('d',1)
insert into test values('e',0)select identity(int,1,1) as id ,* into #tmp1 from test where sex=0
select identity(int,1,1) as id ,* into #tmp2 from test where sex=1
select a.name,case when a.sex=0 then '男' else null end,
b.name,case when b.sex=1 then '女' else null end from #tmp1 a full join #tmp2 b
on a.id=b.id

解决方案 »

  1.   

    我用的是sql server2000
    问题已经解决,我想听各位的高见.
    我的实际问题跟这个很类似,所以虚拟了这个问题.
    数据库中有一个table(不好意思,让大家见笑了)
    (铁诺) ,你很厉害呀,不知道你能不能得到我的尊重.
      

  2.   

    有个情况要告诉大家;我每周只有一天能上网,所以可能回复和结帖的时间长一些.
    但是我一定会把50分给第一个回答正确的朋友.
    newly_ignorant(不学无术) 
    你的代码我还没有检验,但我感觉你的思路是正确的.非常感谢你.
      

  3.   

    select identity(int,1,1) as id,* into #temp from table 
    order by --(你的排序)select a.姓名,a.性别,b.姓名,b.性别 from 
    (select 姓名,性别 from #temp where id%2=1) a --id为单数
    left join 
    (select 姓名,性别 from #temp where id%2=0)  b  --id为双数
    on a.id=b.id+1
      

  4.   

    上面错了,应是:
    on a.id+1=b.id
      

  5.   

    问题已经解决了感谢各位朋友的支持。
    同时感谢j9988(j9988)对本帖的关注。
    为表示感谢,请到
    http://www.csdn.net/expert/topic/1021/1021263.xml?temp=.9305536
    小弟有5分相赠。