所以我需要对 debit_id 和 transfer_id 相等的值“金额”求和: 表示例:
借记卡号 | 转移ID | 金额 | 借方类型
1184685 | 861288 | 25.5 | 2
1184685 | 861288 | 59.5 | 2
1168516 | 861288 | 23 | 0
现在我使用这个查询给了我几乎预期的值
WITH ct AS
( SELECT *,rn = ROW_NUMBER() OVER (PARTITION BY debit_id, transfer_id
ORDER BY id DESC)
FROM transfer_debits
)
SELECT debit_id, transfer_id, amount, debit_type
FROM ct
WHERE rn = 1 AND transfer_id = 861288
ORDER BY debit_id, transfer_id;
我需要这个结果,但是按 debit_id 和 transfer_id 分组的字段金额的总和所需的结果应该是: