WITH daily_data AS (
SELECT
sub_account,
ref_date,
TOTAL_PAYMENTS,
LAG(TOTAL_PAYMENTS) OVER (PARTITION BY sub_account ORDER BY ref_date) AS prev_day_total
FROM AB_MIS2.mis.LGS
WHERE REF_DATE > '2023-12-29'
)
SELECT
sub_account,
ref_date,
COALESCE(TOTAL_PAYMENTS - prev_day_total, TOTAL_PAYMENTS) AS daily_payments
FROM daily_data
WHERE COALESCE(TOTAL_PAYMENTS - prev_day_total, TOTAL_PAYMENTS) <> 0
ORDER BY sub_account, ref_date;
With
Δημοσιεύθηκε στην SQL. Αποθηκεύστε τον μόνιμο σύνδεσμο.