首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求教,这样的查询语句如何写(sql2005)

2013-03-06 
求教,这样的查询语句怎么写(sql2005)表asxhgx1L2Y3M4W针对表a查询出如下结果sxhgxsxh+1gx11L2Y2Y3M3M4W4W

求教,这样的查询语句怎么写(sql2005)
表a
sxh  gx
1     L
2     Y
3     M
4     W
针对表a查询出如下结果
sxh    gx    sxh+1   gx1
1       L      2      Y
2       Y      3      M
3       M      4      W
4       W
其中查询出来的第三列sxh+1是对表a中的sxh+1,gx1是指根据表a中sxh查询出的gx,不知道大家明白没~~~ 我试了几中写法,最后一行查询不出来,请大家不吝指教             sql
[解决办法]
select a1.*,a2.sxh as sxh1,a2.gx as gx1
from a a1 left join a a2
on a2.sxh = a1.sxh + 1  and a2.gxid = a1.gxid
where a1.gxid = 1

热点排行