Compute Daily Cancellations after Excluding Either Banned Participant

Quick Overview

Calculate daily trip cancellation rates over a fixed date range using only requests with an unbanned client and driver.

Compute Daily Cancellations after Excluding Either Banned Participant

Company: Google

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: hard

Interview Round: Other

### Problem For each day from 2013-10-01 through 2013-10-03 inclusive with eligible requests, report Day and Cancellation Rate. A request is eligible only when both its client and driver are unbanned. Divide eligible client-or-driver cancellations by all eligible requests that day, rounding to two decimal places. Row order is unrestricted. ### Tables Table: `Trips` ```text +-------------+----------+ | Column Name | Type | +-------------+----------+ | id | int | | client_id | int | | driver_id | int | | city_id | int | | status | enum | | request_at | varchar | +-------------+----------+ id is the primary key (column with unique values) for this table. The table holds all taxi trips. Each trip has a unique id, while client_id and driver_id are foreign keys to the users_id at the Users table. Status is an ENUM (category) type of ('completed', 'cancelled_by_driver', 'cancelled_by_client'). ``` Table: `Users` ```text +-------------+----------+ | Column Name | Type | +-------------+----------+ | users_id | int | | banned | enum | | role | enum | +-------------+----------+ users_id is the primary key (column with unique values) for this table. The table holds all users. Each user has a unique users_id, and role is an ENUM type of ('client', 'driver', 'partner'). banned is an ENUM (category) type of ('Yes', 'No'). ``` ### Example ```text Users (users_id,banned,role): (1,No,client), (2,Yes,client), (10,No,driver), (11,Yes,driver) Trips (id,client_id,driver_id,city_id,status,request_at): (1,1,10,1,completed,2013-10-01), (2,1,10,1,cancelled_by_client,2013-10-01), (3,2,10,1,cancelled_by_driver,2013-10-01), (4,1,11,1,cancelled_by_driver,2013-10-02) Output (Day,Cancellation Rate): (2013-10-01,0.50) ``` ### What a Strong Answer Covers - Apply the same request eligibility rules to the numerator and denominator. - Count both kinds of cancellation and handle a day with no eligible requests. - Use the specified date range and return rates rounded to two decimal places. ### Follow-up Questions - How would you report calendar days with no eligible requests? - How would the result change if client and driver cancellations needed separate rates?

Overview: Calculate daily trip cancellation rates over a fixed date range using only requests with an unbanned client and driver.

Google logo
Google
Sep 27, 2026
hardSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

For each day from 2013-10-01 through 2013-10-03 inclusive with eligible requests, report Day and Cancellation Rate. A request is eligible only when both its client and driver are unbanned. Divide eligible client-or-driver cancellations by all eligible requests that day, rounding to two decimal places. Row order is unrestricted.

Tables

Table: Trips

+-------------+----------+
| Column Name | Type     |
+-------------+----------+
| id          | int      |
| client_id   | int      |
| driver_id   | int      |
| city_id     | int      |
| status      | enum     |
| request_at  | varchar  |
+-------------+----------+
id is the primary key (column with unique values) for this table.
The table holds all taxi trips. Each trip has a unique id, while client_id and driver_id are foreign keys to the users_id at the Users table.
Status is an ENUM (category) type of ('completed', 'cancelled_by_driver', 'cancelled_by_client').

Table: Users

+-------------+----------+
| Column Name | Type     |
+-------------+----------+
| users_id    | int      |
| banned      | enum     |
| role        | enum     |
+-------------+----------+
users_id is the primary key (column with unique values) for this table.
The table holds all users. Each user has a unique users_id, and role is an ENUM type of ('client', 'driver', 'partner').
banned is an ENUM (category) type of ('Yes', 'No').

Example

Users (users_id,banned,role): (1,No,client), (2,Yes,client), (10,No,driver), (11,Yes,driver)
Trips (id,client_id,driver_id,city_id,status,request_at):
(1,1,10,1,completed,2013-10-01), (2,1,10,1,cancelled_by_client,2013-10-01),
(3,2,10,1,cancelled_by_driver,2013-10-01), (4,1,11,1,cancelled_by_driver,2013-10-02)
Output (Day,Cancellation Rate): (2013-10-01,0.50)

What a Strong Answer Covers Guidance

  • Apply the same request eligibility rules to the numerator and denominator.
  • Count both kinds of cancellation and handle a day with no eligible requests.
  • Use the specified date range and return rates rounded to two decimal places.

Follow-up Questions Guidance

  • How would you report calendar days with no eligible requests?
  • How would the result change if client and driver cancellations needed separate rates?