Keep Customers without a Referee or Referred by Someone Other Than Two

Quick Overview

Return customer names when referee_id is not2, or when no referee is recorded. A NULL referee_id represents no referral and must be retained. No row ordering is required.

Keep Customers without a Referee or Referred by Someone Other Than Two

Company: Google

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

### Problem Return customer names when referee_id is not 2, or when no referee is recorded. A NULL referee_id represents no referral and must be retained. No row ordering is required. ### Tables Table: `Customer` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | | referee_id | int | +-------------+---------+ In SQL, id is the primary key column for this table. Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them. ``` ### Example ```text Customer (id,name,referee_id): (1,Ada,NULL), (2,Bo,2), (3,Cam,1) Output (name): (Ada), (Cam) ``` ### What a Strong Answer Covers - Include customers whose referee is absent or differs from the excluded ID. - Return one name for each qualifying customer, including repeated names. - Handle the case where no customer qualifies. ### Follow-up Questions - How would the condition change if more than one referee ID needed to be excluded? - How would you return the qualifying counts for each referee?

Overview: Return customer names when referee_id is not2, or when no referee is recorded. A NULL referee_id represents no referral and must be retained. No row ordering is required.

Google logo
Google
easySoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return customer names when referee_id is not 2, or when no referee is recorded. A NULL referee_id represents no referral and must be retained. No row ordering is required.

Tables

Table: Customer

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| id          | int     |
| name        | varchar |
| referee_id  | int     |
+-------------+---------+
In SQL, id is the primary key column for this table.
Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.

Example

Customer (id,name,referee_id): (1,Ada,NULL), (2,Bo,2), (3,Cam,1)
Output (name): (Ada), (Cam)

What a Strong Answer Covers Guidance

  • Include customers whose referee is absent or differs from the excluded ID.
  • Return one name for each qualifying customer, including repeated names.
  • Handle the case where no customer qualifies.

Follow-up Questions Guidance

  • How would the condition change if more than one referee ID needed to be excluded?
  • How would you return the qualifying counts for each referee?