Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL: Top Cancellation Regions
00:00
5 left

SQL: Top Cancellation Regions

MediumSQL · PostgreSQL

Problem

Given this dataset of partner transactions, write a query to identify the top three regions with the highest cancellation rates over the last quarter.

Use the previous calendar quarter relative to the query execution date. A cancellation rate is canceled transactions divided by all transactions in the region during that quarter.

Output

  1. One row per selected region with region_name, transaction_count, cancelled_transaction_count, and cancellation_rate_percent
  2. Include only regions with at least one transaction in the quarter
  3. Sort by cancellation rate descending, then region name ascending to break ties

Schema

regions
ColumnTypeDescription
region_idPKINTUnique identifier for a region
region_nameVARCHAR(100)Display name of the region
partner_transactions
ColumnTypeDescription
transaction_idPKINTUnique identifier for a partner transaction
region_idINTRegion associated with the transaction
transaction_dateDATEDate on which the transaction was recorded
statusVARCHAR(20)Transaction status, such as confirmed or cancelled
Tablesregionspartner_transactions
Interviewer

Your question is SQL: Top Cancellation Regions. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.