Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Top Accounts and Risk
00:00
5 left

SQL for Top Accounts and Risk

HardSQL · PostgreSQL

Problem

Write a SQL query to combine operations, customer, and revenue data to identify the top accounts by monthly usage, support tickets, and renewal risk.

Use January and February 2025 data. Include each account's monthly usage, support ticket count, revenue, and renewal risk score. Treat a month-over-month usage decline as an additional renewal risk signal.

Output

  1. Return the top three accounts per month, one row per account and month.
  2. Include month_start, account_id, account_name, monthly_usage, support_tickets, renewal_risk_score, monthly_revenue, and account_rank.
  3. Order by month, rank, and account ID. Break ties by usage, ticket count, risk score, and account ID.

Schema

customer_accounts
ColumnTypeDescription
account_idPKINTUnique customer account identifier
account_nameVARCHAR(100)Customer account name
segmentVARCHAR(30)Customer segment
account_statusVARCHAR(20)Account lifecycle status
usage_events
ColumnTypeDescription
usage_event_idPKINTUnique usage event identifier
account_idINTCustomer account associated with the usage
usage_dateDATEDate of usage
usage_unitsINTUnits consumed during the event
support_tickets
ColumnTypeDescription
ticket_idPKINTUnique support ticket identifier
account_idINTCustomer account that opened the ticket
opened_atDATEDate the ticket was opened
ticket_priorityVARCHAR(20)Support ticket priority
ticket_statusVARCHAR(20)Support ticket status
revenue_contracts
ColumnTypeDescription
account_idPKINTCustomer account identifier
monthly_revenueDECIMAL(12,2)Current monthly recurring revenue
renewal_dateDATEContract renewal date
renewal_risk_scoreINTBase renewal risk score from 0 to 100
Tablescustomer_accountsusage_eventssupport_ticketsrevenue_contracts
Interviewer

Your question is SQL for Top Accounts and Risk. Start with the requirements and the four 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.