Question
I need help creating the following queries in MySQL 1. Suppose you have a database modeling a mobile riding platform somewhat similar to Uber, which
I need help creating the following queries in MySQL
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) DRIVER ( did , dname, city, phone, vehicletype, licenseplate) TRIP ( pid, did, starttime , endtime, startloc, destinationloc, miles, price) Note: pid references pid in PASSENGER, and did references did in DRIVER RATING ( pid, did, starttime, ratertype , score, comment) Note: ( pid, did, starttime ) references ( pid, did, starttime ) in TRIP 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. VII. Find the most expensive trip, and output its price together with the ID and name of the driver(s). VIII. Output the ID of any passenger who has taken at least one trip with every driver from the city of Hackensack. (b) Write statements in Relational Algebra for all eight queries. Use basic RA whenever possible, and extended RA otherwise. (c) Write statements in (Domain or Tuple) Relational Calculus for query I, II, IV, VI, VII, and VIII, or explain if it is not possible to do so. (d) How would you change the schema if a driver can use several vehicles and a vehicle can have several drivers?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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