我有一张这样的表
我希望返回两行之间的差异
答案 0 :(得分:1)
SQL表代表无序集。除非列指定了排序,否则没有排序。
因此,您可以使用MAX()
和MIN()
获取这两个值。这应该做你想要的:
select max(nbaction) - min(nbaction)
from t;
编辑:
鉴于您的实际问题,您有多种选择。这是一个:
SELECT (SELECT nbaction
FROM analyse_page_fait
WHERE operateurdimid = 2
ORDER BY datedimid DESC
FETCH FIRST 1 ROW ONLY
) -
(SELECT nbaction
FROM analyse_page_fait
WHERE operateurdimid = 2
ORDER BY datedimid DESC
OFFSET 1
FETCH FIRST 1 ROW ONLY
) as diff