Question: Note: You can work on the SQL Server to write the below questions SQL Query. 1. Suppose you have a database modeling a mobile riding

Note: You can work on the SQL Server to write the below questions SQL Query.

1. Suppose you have a database modeling a mobile riding platform somewhat similar to Uber, which is given by the following schema:

PASSENGER (pid, pname, city, phone)

Note: pid (Primary Key)

DRIVER (did, dname, city, phone, vehicletype, licenseplate)

Note: did (Primary Key)

TRIP (pid, did, starttime, endtime, startloc, destinationloc, miles, price)

Note: pid references pid in PASSENGER, and did references did in DRIVER (Primary Key: pid, did, starttime)

RATING (pid, did, starttime, ratertype, score, comment)

Note: (pid, did, starttime) references (pid, did, starttime) in TRIP (Primary Key: pid, did, starttime, ratertype)

In this schema, passengers are the people who use this platform to request a ride. Drivers are the people who provide the ride. For the sake of simplicity, each driver can only use one vehicle on this platform. In each trip, there is only one driver and one passenger account involved. The starttime and endtime in the TRIP table show the start time and end time of this trip, respectively. After each trip, both the passenger and the driver have the chance to rate this trip and leave their comments. In the RATING table, ratertype has only two values, passenger or driver. It indicates whether this rating is from the driver or the passenger. A record will be added to the RATING table only when there is a rating. If nobody rates the trip, there will be no record in the RATING table.

(a) Write SQL statements for the following queries.

I. Output the passenger name, driver name, and start time of trips in which the passenger and the driver are from the same city.

II. Output the passenger ID, driver ID, and start time of trips that were completed in 2020. (Meaning: the end time is during 2020)

III. Output the passenger name, driver name, start time, and end time of trips that were more than 4 hours and where the vehicle type was SUV.

IV. Output the ID and name of passengers who live in Brooklyn and have not taken any ride ending in 2020.

V. Output the ID and name of the driver(s) who finished the most rides in 2020.

VI. For each driver, output the total number of rides he/she finished and the number of ratings he/she got from these rides.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!