79235838

Date: 2024-11-29 04:34:00
Score: 0.5
Natty:
Report link

found that this is line made my query working for anybody that care.

customer_month_balances AS ( -- Combine customer-month combinations with their balances SELECT pm."customer_id", pm."month", COALESCE(mb."month_opening_balance", NULL) AS "month_opening_balance", COALESCE(mb."month_closing_balance", NULL) AS "month_closing_balance" FROM customer_months pm LEFT JOIN monthly_balances mb ON pm."customer_id" = mb."customer_id" AND pm."month" = mb."month" ), propagated_balances AS (

SELECT
    customer_id,
    month,
    month_opening_balance,
    month_closing_balance,
    LAST_VALUE(month_closing_balance IGNORE NULLS) OVER (
        PARTITION BY customer_id
        ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) AS propagated_closing_balance
FROM
    customer_month_balances

)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Marinos Kaitis