我有一个带有以下列和样本数据的oracle表DM_TEMP_SUMMING_DVC_BY_FW。 以下数据显示
-dmc_id ='408' there are 2109 devices which are having firmware_version='RT1' and it is the first firmware_version because image_prerequisite is null for this firmware_image.
-dmc_id ='408' there are 40 devices which are having firmware_version='RT2' moved from "RT1" and so on.
+-----------+-------+-----------------+------------+------------------+
device_count| dmc_id| firmware_version| cg_id |image_prerequisite|
+-----------+-------+-----------------+------------+------------------+
| 40 | 408 |RT2 |0000 |RT1 |
| 24 | 408 |RT3 |0000 |RT2 |
| 18 | 408 |RT4 |0000 |RT3 |
| 2109 | 408 |RT1 |0000 |null |
+-----------+-------+-----------------+------------+------------------+
要求是创建firmware_versions链和移动链的设备数量。 例如:
Firmware_version movement is RT1-->RT2-->RT3-->RT4
so the count of devices moved from RT1 to RT4 is (RT1+RT2+RT3+RT4)
count of devices moved from RT2 to RT4 is (RT2+RT3+RT4)
count of devices moved from RT3 to RT4 is (RT3+RT4)
count of devices at last firmware_version is RT4
+--------------------+-------+-----------------+-------+--------------------+
cumm_device_count | dmc_id| firmware_version| cg_id |chain |
+--------------------+-------+-----------------+-------+--------------------+
| 82(40+24+18) | 408 |RT2 |0000 |null/RT1/RT2 |
| 42(24+18) | 408 |RT3 |0000 |null/RT1/RT2/RT3 |
| 18 | 408 |RT4 |0000 |null/RT1/RT2/RT3/RT4|
| 2191(2109+40+24+18)| 408 |RT1 |0000 |null/RT1 |
+--------------------+-------+-----------------+-------+--------------------+
我尝试使用以下查询来生成基于firmware_version和image_prerequisite的链,但它没有按预期返回结果。此查询返回28条记录。
SELECT dmc_id, firmware_version, charging_group_id, image_prerequisite, SYS_CONNECT_BY_PATH(firmware_version,'/') TrackingFW
from DM_TEMP_SUMMING_DVC_BY_FW
where FIRMWARE_VERSION in ('RT1','RT2','RT3','RT4') and dmc_id='408' and charging_group_id='0000'
CONNECT BY NOCYCLE PRIOR firmware_version=image_prerequisite;
请建议查询或程序以解决此要求。
提前致谢!