查看: 1092|回复: 0

[SQLServer] SQL计算上下两行某列的差

发表于 2018-4-27 08:00:05

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 #TempHuDong) as a
LEFT JOIN (select row_number()over(order by getdate()) as id,* from #TempHuDong) as b
ON a.id = b.id - 1



回复

使用道具 举报