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 T (
Account INT,
Date DATE,
Inventory INT
);

INSERT INTO T
VALUES (123,'2019-04-01',5)
,(123,'2019-05-01',6)
,(123,'2019-07-01',9)
,(123,'2019-08-01',5)
,(123,'2019-09-01',8)
,(123,'2019-10-01',9)
,(54321,'2018-01-01',5)
,(54321,'2018-02-01',7)
,(54321,'2018-03-01',5)
,(54321,'2018-04-01',9)
,(54321,'2018-05-01',8)
11 rows affected
select account, max(next_date)
from (select t.*,
lead(date) over (partition by account order by date) as next_date
from t
) t
where inventory = 5
group by account;
account (No column name)
123 2019-09-01
54321 2018-04-01