Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Customers Excluding Segments

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Customers Excluding Segments. Start with the requirements and the three tables on the right.

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.

Problem

Convoy's shipper analytics team needs a customer-level view of delivered load volume. Write a PostgreSQL query to identify the top five customers after excluding loads hauled by specified carrier segments.

Requirements

  1. Count delivered loads per customer as load_volume.
  2. Exclude loads assigned to carriers in the owner_operator or small_fleet segments. Treat a NULL carrier segment as eligible.
  3. Return the five customers with the greatest eligible load volume, breaking ties by customer_name ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer business name
loads
ColumnTypeDescription
load_idPKINTUnique load identifier
customer_idINTCustomer associated with the load
carrier_idINTCarrier assigned to the load
statusVARCHAR(30)Current load status
carriers
ColumnTypeDescription
carrier_idPKINTUnique carrier identifier
segmentVARCHAR(40)Carrier classification segment
Tablescustomersloadscarriers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results