Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A ride hailing company has their DB structured in 3 major tables as described in the SCHEMA section below. Write a query to fetch
A ride hailing company has their DB structured in 3 major tables as described in the SCHEMA section below. Write a query to fetch the top 100 users who traveled the most distance using the service. The output should be structured as: users.name distance_traveled Sort the output by distance traveled in descending order, then by the user name in ascending order. Show only the top 100 users, ignoring the ties at the last position. Note: There could be multiple users with the same name but they will have different IDs. v Schema You are provided 3 tables: CITIES, USERS, and RIDES. CITIES Name Type Description id String The assigned ID to the city presented as 32 character UUID. name String The name of the city. USERS Name Type Description id String The assigned ID to the user presented as 32 character UUID. city_id String The id of the city in which this user resides. name String The name of the user. email String The email of the user. v Sample Data Tables CITIES id name 1 Cooktown South Suzanne USERS id city_id email name 1 2 Robert Delgado robertdelgado@hotmail.com 2 Thomas Williams thomaswilliams@bradley.org 3 1 Michele Peterson michelepeterson@hotmail.com 4 1 Bill Wheeler billwheeler@gmail.com 1 David Lloyd davidlloyd@gmail.com 6. 1 Morgan Powers morganpowers@hansen.biz RIDES id user_id distance fare 1 1 21 200 55 6, 5. 30 230 4 2 16 125 2 11 110 30 285 7 18 170 8 1 50 2 4 40 10 1 10 90 11 11 95 12 16 140 13 3 24 220 14 17 160 15 2 23 205 16 3 11 90 17 50 18 3 19 180 19 22 205 20 6 60 Expected Output Thomas Williams 84 Michele Peterson 78 Morgan Powers 63 David L lovd 38 1 /* 2 Enter your query below. 3 Please append a semicolon ";" at the end of the query 4 */
Step by Step Solution
★★★★★
3.40 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
SELECT TOP 100 USERSnameSUMRIDESdistance AS distancetraveled FROM USERS INNER JOIN RIDES ON RIDESuse...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started