164k views
3 votes
To see the delivery zip code with the most returns, count the total number of order returns per Delivery Zip Code. Show the top five zip codes with their count. ( Use SQL - Postgres )

User OverStack
by
7.7k points

1 Answer

4 votes

Answer:

To find the delivery zip code with the most returns and display the top five zip codes along with their count, you can use the following SQL query in PostgreSQL:

```sql

SELECT "Delivery Zip Code", COUNT(*) as "Return Count"

FROM your_table_name

WHERE "Return" = true

GROUP BY "Delivery Zip Code"

ORDER BY "Return Count" DESC

LIMIT 5;

```

Make sure to replace `your_table_name` with the actual name of your table. This query assumes that your table containing the orders has a column named "Delivery Zip Code" for the zip code and a column named "Return" that indicates if an order was returned or not.

The query first filters for returned orders by checking the value of the "Return" column. It then groups the returned orders by "Delivery Zip Code" and counts the number of occurrences for each zip code. Finally, it orders the results in descending order by the return count and limits the results to the top five zip codes.

User Fantasim
by
7.8k points