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
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
解决方案 »
- 一条SQL的查寻语句,麻烦下。
- 請各位高人幫忙看看這個觸發器怎麼寫,謝謝!
- 按月统计出库情况
- 我想调试sql语句,可打开SQL2005很慢,有没有什么单独的小组件可以使用,因为SQL2005功能太多,所以仅仅测试SQL语句,感觉确实有些大材小用了.
- 邹健请进,如何分析出复杂SQL语句中的主表名和其它表名?
- 疑问:如何复制数据
- 如何只显示每个id的最后一个值?
- 我 要给一个字段前面补0,但是这个字段有的是6位,有的是7位,8位的。类型是varchar(10)
- 数据库无法还原 ,急急急!!!!
- 有没有办法查看一个存储过程最近在什么时间运行过。
- 这句sql的结果是什么?为什么是这样?(很简单)
- 一个库存管理中经常遇到的问题,关于产品的“单号”
问题已经解决,我想听各位的高见.
我的实际问题跟这个很类似,所以虚拟了这个问题.
数据库中有一个table(不好意思,让大家见笑了)
(铁诺) ,你很厉害呀,不知道你能不能得到我的尊重.
但是我一定会把50分给第一个回答正确的朋友.
newly_ignorant(不学无术)
你的代码我还没有检验,但我感觉你的思路是正确的.非常感谢你.
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
on a.id+1=b.id
同时感谢j9988(j9988)对本帖的关注。
为表示感谢,请到
http://www.csdn.net/expert/topic/1021/1021263.xml?temp=.9305536
小弟有5分相赠。