Refund Rate

ASKED IN INTERVIEW
4pts
Shopify

Problem Statement

Shopify Risk Management wants to identify stores with unusually high refund rates.

Write an SQL query to find the refund rate for each store.

Rules:

  • refund_rate = (Orders with status "refunded" / Total Orders) * 100.
  • Round the refund_rate to 2 decimal places.
  • If a store has no orders at all, the refund_rate should be 0.00.
  • Output columns: store_name, refund_rate.
  • Results must be sorted by refund_rate in descending order, then store_name in ascending order.
Tests your understanding of
Conditional Aggregation, Joins and Ratios

Input Tables

Stores
store_id(INTEGER)store_name(VARCHAR)
1Urban Threads
2Tech Haven
3Green Sprout
Orders
order_id(INTEGER)store_id(INTEGER)status(VARCHAR)
11refunded
21completed
31completed
42refunded
52completed

Expected Output

store_name(VARCHAR)refund_rate(DECIMAL)
Tech Haven50
Urban Threads33.33
Green Sprout0

Tags

MediumASKED IN INTERVIEWConditional AggregationJoinsRatios
10-15 min
71%

Hints