有谁知道如何仅使用一个 id 从一列中减去前两行?这是我的示例查询:
SELECT top 2 a.consumption,
coalesce(a.consumption -
(SELECT b.consumption
FROM tbl_t_billing b
WHERE b.id = a.id + 1), a.consumption) AS diff
FROM tbl_t_billing a
WHERE a.customerId = '5'
ORDER BY a.dateCreated DESC
我想知道如何使用 customerId #5 从消费列中的一个 id 获取前 2 行之间的差异。我已经尝试过,但我无法获得正确的查询。有人可以帮我吗?谢谢!