I have the following table called Tracking:
ID_path -- step_start -- step_end -- time
1 A B 10
1 B C 20
1 C D 30
2 A C 100
3 D C 20
3 A N 300
I'm looking for a single query in Mysql that can extract the cumulate value for path A-C, so itself and all step inside: [A-C] + [A-B] + [B-C].
Select sum(time) from tracking where (step_start = 'A' or step_end = 'C') and ID_path = ID_path
I thought this query considering that the value of step can't be both in start and end but I don't know how to express the last condition (ID_path = ID_path) in order to extract only the record that have the same id_path. Is there a specific SQL function?
Thanks for any help / mysql coding guidelines / advice