Попробуйте это:
WITH
TAB (ID, READING, STARTDATE, TYPE) AS
(
VALUES
(1010, 250, DATE('2020-01-05'), 'XXX')
, (1010, 500, DATE('2020-01-12'), 'XXX')
, (1010, 680, DATE('2020-01-20'), 'XXX')
, (1011, 100, DATE('2020-02-08'), 'YYY')
, (1011, 340, DATE('2020-02-11'), 'YYY')
, (1011, 180, DATE('2020-02-12'), 'YYY')
)
SELECT
ID, DATE_MONTH, SUM(CASE TYPE WHEN 'XXX' THEN READING END) FSUM, FIRSTREADING, LASTREADING, TYPE
FROM
(
SELECT
ID
, to_char(STARTDATE, 'Mon YYYY', 'en_US') DATE_MONTH
, STARTDATE, READING, TYPE
, FIRST_VALUE (CASE TYPE WHEN 'YYY' THEN READING END, 'IGNORE NULLS') OVER (PARTITION BY ID, to_char(STARTDATE, 'Mon YYYY', 'en_US') ORDER BY STARTDATE) FIRSTREADING
, FIRST_VALUE (CASE TYPE WHEN 'YYY' THEN READING END, 'IGNORE NULLS') OVER (PARTITION BY ID, to_char(STARTDATE, 'Mon YYYY', 'en_US') ORDER BY STARTDATE DESC) LASTREADING
FROM TAB
)
GROUP BY ID, DATE_MONTH, FIRSTREADING, LASTREADING, TYPE;