By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE mytable(
Id INTEGER NOT NULL PRIMARY KEY
,Type VARCHAR(6) NOT NULL
,OrderDate DATE NOT NULL
);
INSERT INTO mytable(Id,Type,OrderDate) VALUES (1,'A','2019-03-01');
INSERT INTO mytable(Id,Type,OrderDate) VALUES (2,'B','2019-03-04');
INSERT INTO mytable(Id,Type,OrderDate) VALUES (3,'B','2019-03-04');
INSERT INTO mytable(Id,Type,OrderDate) VALUES (4,'A','2019-03-05');
INSERT INTO mytable(Id,Type,OrderDate) VALUES (5,'A','2019-03-06');
INSERT INTO mytable(Id,Type,OrderDate) VALUES (6,'B','2019-04-05');
select
id,
type,
(
select min(OrderDate)
from mytable t1
where t1.Type = 'B' and t1.OrderDate >= t.OrderDate
) NextOrderBDate
from mytable t
where type = 'A'
id | type | NextOrderBDate |
---|---|---|
1 | A | 2019-03-04 |
4 | A | 2019-04-05 |
5 | A | 2019-04-05 |