add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE table_name (ID, "DATE", Amount) AS
SELECT 1, DATE '2020-12-29', 6 FROM DUAL UNION ALL
SELECT 1, DATE '2021-01-05', 5 FROM DUAL UNION ALL
SELECT 1, DATE '2021-02-15', 7 FROM DUAL UNION ALL
SELECT 2, DATE '2021-04-11', 9 FROM DUAL UNION ALL
SELECT 2, DATE '2021-05-27', 8 FROM DUAL UNION ALL
SELECT 2, DATE '2021-05-29', 7 FROM DUAL;
6 rows affected
SELECT d.id,
d.dt AS "DATE",
COALESCE(
LAST_VALUE(t.amount)
IGNORE NULLS OVER (PARTITION BY d.id ORDER BY d.dt),
0
) AS amount
FROM table_name t
RIGHT OUTER JOIN (
WITH date_ranges (id, dt, max_dt) AS (
SELECT id,
TRUNC(MIN("DATE"), 'MM'),
LAST_DAY(TRUNC(MAX("DATE"), 'MM'))
FROM table_name
GROUP BY id
UNION ALL
SELECT id, dt + 1, max_dt
FROM date_ranges
WHERE dt < max_dt
)
SELECT id, dt
FROM date_ranges
) d
ON (t.id = d.id AND t."DATE" = d.dt)
ORDER BY id, "DATE"
ID DATE AMOUNT
1 01-DEC-20 0
1 02-DEC-20 0
1 03-DEC-20 0
1 04-DEC-20 0
1 05-DEC-20 0
1 06-DEC-20 0
1 07-DEC-20 0
1 08-DEC-20 0
1 09-DEC-20 0
1 10-DEC-20 0
1 11-DEC-20 0
1 12-DEC-20 0
1 13-DEC-20 0
1 14-DEC-20 0
1 15-DEC-20 0
1 16-DEC-20 0
1 17-DEC-20 0
1 18-DEC-20 0
1 19-DEC-20 0
1 20-DEC-20 0
1 21-DEC-20 0
1 22-DEC-20 0
1 23-DEC-20 0
1 24-DEC-20 0
1 25-DEC-20 0
1 26-DEC-20 0
1 27-DEC-20 0
1 28-DEC-20 0
1 29-DEC-20 6
1 30-DEC-20 6
1 31-DEC-20 6
1 01-JAN-21 6
1 02-JAN-21 6
1 03-JAN-21 6
1 04-JAN-21 6
1 05-JAN-21 5
1 06-JAN-21 5
1 07-JAN-21 5
1 08-JAN-21 5
1 09-JAN-21 5
1 10-JAN-21 5
1 11-JAN-21 5
1 12-JAN-21 5
1 13-JAN-21 5
1 14-JAN-21 5
1 15-JAN-21 5
1 16-JAN-21 5
1 17-JAN-21 5
1 18-JAN-21 5
1 19-JAN-21 5
1 20-JAN-21 5
1 21-JAN-21 5
1 22-JAN-21 5
1 23-JAN-21 5
1 24-JAN-21 5
1 25-JAN-21 5
1 26-JAN-21 5
1 27-JAN-21 5
1 28-JAN-21 5
1 29-JAN-21 5
1 30-JAN-21 5
1 31-JAN-21 5
1 01-FEB-21 5
1 02-FEB-21 5
1 03-FEB-21 5
1 04-FEB-21 5
1 05-FEB-21 5
1 06-FEB-21 5
1 07-FEB-21 5
1 08-FEB-21 5
1 09-FEB-21 5
1 10-FEB-21 5
1 11-FEB-21 5
1 12-FEB-21 5
1 13-FEB-21 5
1 14-FEB-21 5
1 15-FEB-21 7
1 16-FEB-21 7
1 17-FEB-21 7
1 18-FEB-21 7
1 19-FEB-21 7
1 20-FEB-21 7
1 21-FEB-21 7
1 22-FEB-21 7
1 23-FEB-21 7
1 24-FEB-21 7
1 25-FEB-21 7
1 26-FEB-21 7
1 27-FEB-21 7
1 28-FEB-21 7
2 01-APR-21 0
2 02-APR-21 0
2 03-APR-21 0
2 04-APR-21 0
2 05-APR-21 0
2 06-APR-21 0
2 07-APR-21 0
2 08-APR-21 0
2 09-APR-21 0
2 10-APR-21 0
2 11-APR-21 9
2 12-APR-21 9
2 13-APR-21 9
2 14-APR-21 9
2 15-APR-21 9
2 16-APR-21 9
2 17-APR-21 9
2 18-APR-21 9
2 19-APR-21 9
2 20-APR-21 9
2 21-APR-21 9
2 22-APR-21 9
2 23-APR-21 9
2 24-APR-21 9
2 25-APR-21 9
2 26-APR-21 9
2 27-APR-21 9
2 28-APR-21 9
2 29-APR-21 9
2 30-APR-21 9
2 01-MAY-21 9
2 02-MAY-21 9
2 03-MAY-21 9
2 04-MAY-21 9
2 05-MAY-21 9
2 06-MAY-21 9
2 07-MAY-21 9
2 08-MAY-21 9
2 09-MAY-21 9
2 10-MAY-21 9
2 11-MAY-21 9
2 12-MAY-21 9
2 13-MAY-21 9
2 14-MAY-21 9
2 15-MAY-21 9
2 16-MAY-21 9
2 17-MAY-21 9
2 18-MAY-21 9
2 19-MAY-21 9
2 20-MAY-21 9
2 21-MAY-21 9
2 22-MAY-21 9
2 23-MAY-21 9
2 24-MAY-21 9
2 25-MAY-21 9
2 26-MAY-21 9
2 27-MAY-21 8
2 28-MAY-21 8
2 29-MAY-21 7
2 30-MAY-21 7
2 31-MAY-21 7