I have two tables one with Purchase ID with month of amount purchased. Another one with calendar. I need to find the running total to the current month with the missing months. I tried the below query but I am not getting correct result. Not sure if its possible in a singe query . Can you please suggest.
Input : Sales
Input: Calendar
I need to find the running total like below.
Output:
QUERY Tried
SELECT PID,b.CALMONTH,SUM("AMOUNT") OVER(PARTITION BY "PID" ORDER BY a."YEAR_MONTH") running_total
FROM SALES a RIGHT JOIN (SELECT YEAR_MONTH CALMONTH FROM CALENDAR
WHERE CALMONTH BETWEEN '201901' and TO_CHAR(CURRENT_TIMESTAMP,'YYYYMM')) b
ON a.CALMONTH=b.CALMONTH



