69.4k views
0 votes
The instantride driver relationship team requires the detail of the drivers who have used more than one car for rides more than twice. Send them the driver_id with the calculated count of used cars, displayed as cars, in decreasing order. Query the drivers that have used more than one car more than once?

User Djhayman
by
7.5k points

1 Answer

4 votes

Final answer:

To find drivers who have used more than one car for rides more than twice, you can use a SQL query to select the driver_id and count the number of distinct car_ids each driver has used.

Step-by-step explanation:

To find the drivers who have used more than one car for rides more than twice, you can use the following SQL query:

SELECT driver_id, COUNT(DISTINCT car_id) AS cars FROM instantride_table GROUP BY driver_id HAVING COUNT(DISTINCT car_id) > 1 AND COUNT(*) > 2 ORDER BY cars DESC;

This query selects the driver_id and counts the number of distinct car_ids each driver has used. It then filters for drivers who have used more than one car (COUNT(DISTINCT car_id) > 1) and have taken more than two rides (COUNT(*) > 2), and finally orders the results in descending order of the number of cars used.

User Jordi
by
8.3k points