Do you find this resource helpful? Treat the author to a coffee! ☕ Your support is the best motivation for creating new content.Support the author →
SQL code copied to buffer
Task 58:

Zones with Unusually High Cost per Mile

Your goal is to analyze the trip costs from the yellow_tripdata table. You need to calculate the average amount per mile for each PULocationID that has at least 100 trips, and compare it to the overall average amount per mile. The output should include the following columns:
- PULocationID: The ID of the pickup location.
- trip_count: The total number of trips for that location.
- average_amount_per_mile: The average amount charged per mile, rounded to two decimal places.
- above_overall_percentage: The percentage by which the average amount per mile exceeds the overall average, rounded to two decimal places.

Sort the results by average_amount_per_mile in descending order.

Use DuckDB syntax to write your answer. Descriptions of tables are provided in the right pane.

Write your request in the field below and click the "Check it!" button.
Get hint
Copy code Clear editor

Hi! Could we please enable some services and cookies to improve your experience and our website?

Privacy & Cookie Policy.