高手,请问这样的SQL如何实现?
表结构是这样的
字段 a b c d
记录 1 x1 y1 z1
1 x2 y2 z2
1 x3 y3 z3
2 x4 y4 z4
2 x5 y5 z5
2 x6 y6 z6
3 x7 y7 z7
记录的规律是基本三条记录一个同样的序号
现在想实现的查询是:
字段: a b c d e f g h i j
1 x1 y1 z1 x2 y2 z2 x3 y3 z3
2 x4 y4 z4 x5 y5 z5 x6 y6 z6
3 x7 y7 z7 .......
请高手给指教,写下如何实现这种查询的SQL,谢谢!
问题点数:0、回复次数:5Top
1 楼631799(杭州工人)回复于 2004-12-03 20:19:34 得分 0
咦,怎么没有分啊?Top
2 楼631799(杭州工人)回复于 2004-12-03 21:14:53 得分 0
看来没人回答了.Top
3 楼631799(杭州工人)回复于 2004-12-03 21:15:59 得分 0
记得要给我分啊!
select *,pid=identity(int,1,1) into #tb from tb
select a.a,a.b,a.c,a.d,b.e,b.f,b.g,c.h,c.i,c.j
from (select a,b,c,d,pid from #tb where pid%3 =1) a left join (select b e,c f,d g,pid from #tb where pid%3=2) b on a.pid=b.pid-1
left join (select b h,c i,d j,pid from #tb where pid%3=0) c on b.pid=c.pid-1Top
4 楼lsxaa(小李铅笔刀)回复于 2004-12-03 21:45:56 得分 0
select aa.a,aa.b,aa.c,aa.d,
bb.b as e,bb.c as f,bb.d as g,
cc.b as h,cc.c as i,cc.d as j
from t aa,t bb,t cc
where checksum(aa.a,aa.b,aa.c,aa.d)
=(select top 1 checksum(aa.a,aa.b,aa.c,aa.d)
from t
where a=aa.a)Top
5 楼lsxaa(小李铅笔刀)回复于 2004-12-03 21:46:28 得分 0
select aa.a,aa.b,aa.c,aa.d,
bb.b as e,bb.c as f,bb.d as g,
cc.b as h,cc.c as i,cc.d as j
from t aa,t bb,t cc
where checksum(aa.a,aa.b,aa.c,aa.d)
=(select top 1 checksum(aa.a,aa.b,aa.c,aa.d)
from t
where a=aa.a) and aa.a=bb.a and aa.a=cc.a
Top




