34,576
社区成员
发帖
与我相关
我的任务
分享
with tb as(
select id=1,num=10 union all
select 2,20 union all
select 3,21 union all
select 4,23 union all
select 5,30
),
cte as(
select *,row=ROW_NUMBER()over(order by id) from tb
)select c1.id,c1.num,c1.num-c2.num from cte c1 left join cte c2 on c1.row=c2.row+1