найти общую длину провисания, если destination_id равен source_id следующей строки - PullRequest
0 голосов
/ 05 июля 2019
if destination_id =source_id then end_slack_length+start_slack_length
else no destination_id for the soucre_id which is matching than start_slack_length
else no source id matches with destination id  then end_slack_length

select  e.source_struct_id, e.desti_struct_id,
case when(select m.end_slack_lenght from icw.TRACE_table m where m.desti_struct_id= e.source_struct_id ) is not null
THEN ( e.start_slack_length+(select m.end_slack_lenght from icw.TRACE_table m where m.desti_struct_id= e.source_struct_id )) 

ELSE e.start_slack_length
 END AS avgslacklength
from icw.TRACE_tablee 
;

TRACE_table

| source_struct_id | desti_struct_id | start_slack_length | end_slack_lenght |
|------------------|-----------------|--------------------|------------------|
|              301 |             302 |                110 |              120 |
|              302 |             303 |                130 |              140 |
|              303 |             304 |                150 |              160 |
|              304 |             305 |                170 |              180 |

Ожидаемый вывод:

301 110                
302 250
303 290
304 310
305 180

Но фактический вывод:

301 110
302 250
303 290
304 310
...