Используйте dense_rank()
для перечисления строк:
select case lag(emp_id) over( order by emp_id ) when emp_id then null
else '<'||dense_rank() over (order by emp_id)||'>'
end sn,
nullif(emp_id, lag(emp_id) over( order by emp_id )) empid,
row_number() over (partition by emp_id order by emp_id) rn,
family_mem_id memid,
case lag(emp_id) over(order by emp_id) when emp_id then null
else (sum(amount_paid) over(partition by emp_id))
end total
FROM Employee order by emp_id;
dbfiddle и пример вывода:
SN EMPID RN MEMID TOTAL
---- ----- ------ ----- ----------
<1> 101 1 F901 200
2 F904
<2> 102 1 F901 135
2 F901
<3> 103 1 F901 185
2 F901
3 F901