For at få hele summen for individuel KPI-kode på hver række, kan du bruge en join som nedenfor:
select data_detail.kpi_code,data_detail.result_data,derived.total_data
from (
SELECT kpi_code, SUM(result_data) AS total_data
FROM data_detail
group by kpi_code
) derived
join data_detail
on derived.kpi_code = data_detail.kpi_code
En fungerende DB Fiddle:https://www.db-fiddle.com/f/ rSe1MVSsJ7uz63XvJsQUkJ/0