From 75129d4e4c79c595c79ad4e565643f14bb2fffb8 Mon Sep 17 00:00:00 2001 From: Colum Kelly <98435978+columk1@users.noreply.github.com> Date: Sun, 21 Jul 2024 23:15:12 -0700 Subject: [PATCH 1/2] Add missing solution --- solutions.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/solutions.sql b/solutions.sql index 0f77c00..e36207c 100644 --- a/solutions.sql +++ b/solutions.sql @@ -764,3 +764,18 @@ WHERE S1.name = 'Craiglockhart' AND R1.company = R2.company AND R1.num = R2.num AND R2.stop = S2.id; + +-- 10. Find the routes involving two buses that can go from Craiglockhart to Lochend. +-- Show the bus no. and company for the first bus, the name of the stop for the transfer, +-- and the bus no. and company for the second bus. +SELECT R1.num, R1.company, S2.name, R4.num, R4.company +FROM route R1 +JOIN route R2 ON (R1.company = R2.company AND R1.num = R2.num) +JOIN route R3 ON (R2.stop = R3.stop) +JOIN route R4 ON (R3.company = R4.company AND R3.num = R4.num) +JOIN stops S1 ON R1.stop = S1.id +JOIN stops S2 ON R2.stop = S2.id +JOIN stops S3 ON R3.stop = S3.id +JOIN stops S4 ON R4.stop = S4.id +WHERE S1.name = 'Craiglockhart' AND S4.name = 'Lochend' +ORDER BY R1.num, S2.name, R4.num From d4b54444135fb24315a04b5f3dd42c5b14c9edb4 Mon Sep 17 00:00:00 2001 From: Colum Kelly <98435978+columk1@users.noreply.github.com> Date: Sun, 21 Jul 2024 23:19:13 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index ec9d592..977615d 100644 --- a/README.md +++ b/README.md @@ -874,3 +874,19 @@ WHERE S1.name = 'Craiglockhart' AND R1.num = R2.num AND R2.stop = S2.id; ``` +10. Find the routes involving two buses that can go from Craiglockhart to Lochend. +Show the bus no. and company for the first bus, the name of the stop for the transfer, +and the bus no. and company for the second bus. +```sql +SELECT R1.num, R1.company, S2.name, R4.num, R4.company +FROM route R1 +JOIN route R2 ON (R1.company = R2.company AND R1.num = R2.num) +JOIN route R3 ON (R2.stop = R3.stop) +JOIN route R4 ON (R3.company = R4.company AND R3.num = R4.num) +JOIN stops S1 ON R1.stop = S1.id +JOIN stops S2 ON R2.stop = S2.id +JOIN stops S3 ON R3.stop = S3.id +JOIN stops S4 ON R4.stop = S4.id +WHERE S1.name = 'Craiglockhart' AND S4.name = 'Lochend' +ORDER BY R1.num, S2.name, R4.num +```