欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL计算上下两行某列的差

程序员文章站 2022-06-17 20:35:24
SELECT * FROM #TempHuDong SELECT * FROM #TempHuDong SELECT TOP 1 ABS(a.num -b.num) '差' FROM (select row_number()over(order by getdate()) as id,* from ......

SELECT * FROM #TempHuDong

SQL计算上下两行某列的差

 

SELECT * FROM #TempHuDong
SELECT TOP 1 ABS(a.num -b.num) '差'
FROM (select row_number()over(order by getdate()) as id,* from #TempHuDong) as a
LEFT JOIN (select row_number()over(order by getdate()) as id,* from #TempHuDong) as b
ON a.id = b.id - 1

SQL计算上下两行某列的差