Question: 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 fSample Data Tables CITIES id name 1Cooktown 2South Suzanne USERS id city_id name email 1N Robert Delgado robertdelgado@hot3 230 230 42 16 125 un 211 110 66 30 285 73 18 170 00 16 50 92 440 10 110 90 11 611 95 12 516 140 13 324 220 14 6

1 2/* Enter your query below. Please append a semicolon ; at the end of the query */ 34

 

 

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

1 Expert Approved Answer
Step: 1 Unlock

To create the SQL query that fetches the top 100 users based on the total distance traveled follow t... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!