🚀 November has started! SQLtest.online stays free thanks to donations from people like you. Help us reach this month's goal early so the site keeps running without interruptions. Support now →
SQL code copied to buffer
Task 18:

Zones with Unusually High Cost per Mile

DuckDB
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.
Expected result Columns: 4 · Rows: 80
PULocationID trip_count average_amount_per_mile above_overall_percentage

Sample rows open after wrong checks: 0 of 2

Write your query below and click "Check it!". Tables are described in the right pane.

Tutorial

By checking a query, you agree that it is stored without your account details and may be included in anonymized datasets, including for AI training. Learn more

The query result will appear here. Ctrl+Enter - Run query