Ivy Professional School
Rating
Learning/SQL Data Drill #19

Ropeway Station Route Analysis

Last updated

Find valid ropeway transportation routes where altitude decreases from start point to middle point to end point.

SQLAdvancedCTESELF JOINCASE WHENINNER JOINRoute AnalysisGraph-style Query

Your Objective

Find valid ropeway transportation routes where altitude decreases from start point to middle point to end point.

The Setup

Your dataset contains two ropeway network tables: 1. A Ropeway_Stations table with station IDs, station names, and altitude 2. A Stations table with directly connected ropeway station pairs Analyze the ropeway station network and identify valid transportation routes for moving rocks from a higher-altitude point to a lower-altitude point. Each route in the Stations table is bidirectional.

Table Schema

Ropeway_Stations
ColumnTypeKey / Notes
idINTEGER
nameVARCHAR(40)
altitudeINTEGER
Stations
ColumnTypeKey / Notes
point1INTEGER
point2INTEGER

Sample Data

Ropeway_Stations — 5 rows

idnamealtitude
1Girijesh1900
2Gandhamadhan2100
3Himadri1600
4Indrakeel782
5Nagaja1370

Stations — 5 rows

point1point2
13
32
35
45
15

Your Task

Ropeway Route Analysis: Which triplets of stations can be used as startpt, middlept, and endpt, where altitude decreases at every step? The route should satisfy: start point altitude > middle point altitude > end point altitude. The final result table should have startpt, middlept, and endpt columns.

Your output should look like this (partial example):

startptmiddleptendpt
GirijeshHimadriNagaja
GandhamadhanHimadriNagaja
HimadriNagajaIndrakeel

Before You Solve

  • →Treat every connection in the Stations table as bidirectional.
  • →First standardize each direct connection so it points from the higher-altitude station to the lower-altitude station.
  • →Use CASE WHEN to choose the downhill start and end point for each edge.
  • →Self join the standardized downhill edges to find two-step routes where the first edge ends where the second edge starts.
Explore Enterprise Solutions