日期:2014-05-17  浏览次数:20456 次

再请教一个sql语句
表A
字段1 字段2
a +
b +
c -
d +
e -
f +
g +
h +
i -
j +
k +
如何将 + 和 - 相邻的两条数据,合并成一条放入新的数据库
1 b c
2 d e
3 h i

------解决方案--------------------
select x.字段1,y.字段1
from
(
select *,ROW_NUMBER() over(order by 字段1) as rowid
from A 
) as X ,(
select *,ROW_NUMBER() over(order by 字段1) as rowid
from A 
) as Y 
where x.rowid=y.rowid+1 and x.字段2='+' and Y.字段2='-'