Вы можете использовать приведенное ниже, чтобы получить результаты
WITH data
AS (SELECT * FROM YOUR_TABLE),
d1
AS (SELECT entry_id,
Max(line_number)
over(
PARTITION BY entry_id
ORDER BY entry_id) line_number,
detailed_comment,
account_id
FROM data)
SELECT d1.entry_id,
d1.line_number,
data.entered_by entered_by,
d1.detailed_comment,
d1.account_id
FROM d1,
data
WHERE d1.entry_id = data.entry_id
AND d1.line_number = data.line_number;
Сначала создайте резервную копию таблицы, используя create test_backup as select * from test
, а затем выполните приведенный ниже оператор MERGE
MERGE INTO TEST s
USING (
SELECT distinct entry_id,
Max(line_number)
over(
PARTITION BY entry_id
ORDER BY entry_id) line_number,
detailed_comment,
account_id
FROM TEST
) t
ON (t.entry_id = s.entry_id )
WHEN MATCHED THEN
UPDATE SET s.entered_by= decode(s.line_number,t.line_number,s.entered_by,null),
s.line_number=t.line_number
И второй запуск приведенный ниже оператор MERGE
MERGE INTO TEST s
USING (
SELECT distinct entry_id, Max(entered_by)
over(
PARTITION BY entry_id
ORDER BY entry_id) entered_by,
detailed_comment,
account_id
FROM TEST
) t
ON (t.entry_id = s.entry_id)
WHEN MATCHED THEN
UPDATE SET s.entered_by=t.entered_by;
и COMMIT;