SQLSERVER,如何取出指定行的上一行,求帮忙

取出name = 'a'的行,并取出该行的上一行数据?请问sql server怎么写?感谢

image.png

用户m2896739 发布于 2021-9-17 16:25
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
黄源Lv6中级互助
发布于2021-9-17 16:35(编辑于 2021-9-17 16:38)

with table1 as(

select * from table where name='a'

)

select  t.* from table t

left join table1 t1 on  t1.rank-1=t.rank

where t1.rank-1=t.rank

union all 

select * from table1

最佳回答
0
Z4u3z1Lv6专家互助
发布于2021-9-17 16:38

image.png

  • 2关注人数
  • 401浏览人数
  • 最后回答于:2021-9-17 16:38
    请选择关闭问题的原因
    确定 取消
    返回顶部