Вы можете попробовать это.
вам нужно только написать подзапрос в select
и получить MIN
дату из BB
таблицы.
CREATE TABLE AA(
ID INT,
"DATE" DATE
);
INSERT INTO AA VALUES(1,to_date('2018-01-21','yyyy-MM-dd'));
INSERT INTO AA VALUES(2,to_date('2018-01-22','yyyy-MM-dd'));
INSERT INTO AA VALUES(2,to_date('2018-05-27','yyyy-MM-dd'));
INSERT INTO AA VALUES(2,to_date('2018-07-15','yyyy-MM-dd'));
CREATE TABLE BB(
ID INT,
"DATE" DATE
);
INSERT INTO BB VALUES(1,to_date('2017-05-21','yyyy-MM-dd'));
INSERT INTO BB VALUES(1,to_date('2017-08-27','yyyy-MM-dd'));
INSERT INTO BB VALUES(1,to_date('2018-01-23','yyyy-MM-dd'));
INSERT INTO BB VALUES(1,to_date('2018-02-15','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2017-01-01','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2017-05-31','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2018-01-01','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2018-01-25','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2018-05-29','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2018-07-31','yyyy-MM-dd'));
INSERT INTO BB VALUES(2,to_date('2018-09-30','yyyy-MM-dd'));
Запрос 1 :
SELECT a1.Id,(
SELECT MIN(b1."DATE")
FROM BB b1
where a1.ID = b1.ID and b1."DATE" >= a1."DATE"
) "Date"
FROM AA a1
Результаты
| ID | Date |
|----|----------------------|
| 1 | 2018-01-23T00:00:00Z |
| 2 | 2018-01-25T00:00:00Z |
| 2 | 2018-05-29T00:00:00Z |
| 2 | 2018-07-31T00:00:00Z |