Единствено с проба и грешка върху вашите примерни данни от SQL Fiddle, това е заявката, която връща очакваните ви данни:
SELECT SYS_CONNECT_BY_PATH(firmware_version, '/') path_,
firmware_version,
device_count,
dmc_id,
charging_group_id,
IMAGE_PREREQUISITE,
(SELECT SUM(device_count)
FROM DM_TEMP_SUMMING_DVC_BY_FW t2
START WITH t1.firmware_version = t2.firmware_version
and T1.dmc_id = T2.dmc_id
and T1.charging_group_id = T2.charging_group_id
CONNECT BY nocycle PRIOR firmware_version=image_prerequisite and prior dmc_id = dmc_id and prior charging_group_id = charging_group_id
) sum_device
FROM DM_TEMP_SUMMING_DVC_BY_FW t1
START WITH image_prerequisite IS NULL
CONNECT BY nocycle PRIOR firmware_version = image_prerequisite
and prior dmc_id = dmc_id
and prior charging_group_id = charging_group_id
Забележка: Да, charging_group_id
и dmc_id
са много важни за вашия очакван резултат, както krokodilko правилно спомена в горния си коментар.