Попробуйте как есть:
WITH TAB (date, refnumber, seq_no, text) AS
(
VALUES
('20200310', '016', '01', 'emp1')
, ('20200310', '016', '01', 'emp1')
, ('20200310', '016', '02', 'row2')
, ('20200310', '016', '02', 'row2')
, ('20200310', '016', '03', 'row3')
, ('20200310', '016', '04', 'act ')
, ('20200310', '016', '04', 'act ')
, ('20200310', '016', '05', 'row4')
, ('20200310', '016', '05', 'row5')
, ('20200310', '018', '01', 'emp1')
, ('20200310', '018', '01', 'emp1')
, ('20200310', '018', '02', 'row2')
, ('20200310', '018', '02', 'row2')
, ('20200310', '018', '03', 'row3')
, ('20200310', '018', '04', 'row4')
, ('20200310', '018', '04', 'row4')
, ('20200310', '018', '05', 'row4')
, ('20200310', '018', '05', 'row5')
)
SELECT
DATE, REFNUMBER
, LISTAGG(CAST(TEXT AS VARCHAR(3000)), '|') WITHIN GROUP (ORDER BY CAST(SEQ_NO AS INT)) AS MESSAGE_TEXT
FROM
(
SELECT DISTINCT DATE(TO_DATE(DATE, 'YYYYMMDD')) AS DATE, REFNUMBER, SEQ_NO, TEXT
FROM TAB
--WHERE DATE(TO_DATE(date, 'YYYYMMDD')) BETWEEN DATE('2020-03-10') - 18 MONTHS AND DATE('2020-03-10') - 1
)
GROUP BY DATE, REFNUMBER
--HAVING COUNT(CASE WHEN text IN (comma separated list of records) THEN 1 END) > 0
ORDER BY DATE;
Результат:
|DATE |REFNUMBER|MESSAGE_TEXT |
|----------|---------|----------------------------------------------------------------------------------------------------|
|2020-03-10|016 |emp1|row2|row3|act |row4|row5 |
|2020-03-10|018 |emp1|row2|row3|row4|row4|row5 |