Hello, I need help with a query.
I need to find the Sum of Distance of T# 1
But there isn't Adelaide -> Melbourne
So I'll have to take the value of Melbourne -> Adelaide which is 400
How can I handle this problem?
I can do them in a seperate query, but how do I get a sum of both?
Or if there's a different approach to this, please advise!
Thanks!
select sum(dist)
from distance d, tripleg t
where (t.origin=d.origin and t.destination = d.destination)
and t#=1;
select sum(dist)
from distance dd, tripleg t
where (t.origin=dd.destination and t.destination = dd.origin)
and t#=1;
SQL> select * from tripleg;
T# LEG# ORIGIN DESTINATION
-- ---------- ------------------------------ -----------
1 1 Sydney Melbourne
1 2 Melbourne Hobart
1 3 Hobart Perth
1 4 Perth Adelaide
1 5 Adelaide Melbourne
1 6 Melbourne Wollongong
SQL> select * from distance;
ORIGIN DESTINATION DIST
------------------------------ ------------------------------ ----------
Sydney Melbourne 1000
Sydney Hobart 1500
Sydney Perth 2000
Sydney Brisbane 1300
Sydney Adelaide 1200
Sydney Wollongong 100
Sydney Newcastle 120
Melbourne Hobart 500
Melbourne Perth 2200
Melbourne Brisbane 2300
Melbourne Adelaide 400
Melbourne Wollongong 950
Melbourne Newcastle 1120
Hobart Perth 2700
Hobart Brisbane 2350
Hobart Adelaide 600
Hobart Wollongong 1300
Hobart Newcastle 1620
Perth Brisbane 2500
Perth Adelaide 1400
Perth Wollongong 2050
Perth Newcastle 1980
Brisbane Adelaide 2150
Brisbane Wollongong 1360
Brisbane Newcastle 1800
Adelaide Wollongong 1200
Adelaide Newcastle 1320
Wollongong Newcastle 120
28 rows selected.