Win rate by sales rep

conditional logic

Win rate by sales rep

Salesforce SQL Interview Question

Salesforce's sales operations team measures each rep's win rate: of the deals that have finished, how many did the rep win?

Find each sales_rep and their win rate as win_rate_pct, rounded to 1 decimal place. The win rate is the percentage of a rep's closed deals that were won. Deals that are still open do not count.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Analytics Engineer

opportunitiesTable12 rows

Column NameType
opportunity_idBIGINT
account_nameVARCHAR
sales_repVARCHAR
stageVARCHAR
amountBIGINT
created_dateDATE
close_dateDATE

opportunitiesExample Input

opportunity_idaccount_namesales_repstageamountcreated_dateclose_date
1Acme CorpPriya NairClosed Won480002024-01-082024-02-19
2GlobexPriya NairClosed Lost220002024-01-152024-03-01
3InitechMarcus HillClosed Won150002024-01-202024-02-10
4Umbrella HealthMarcus HillClosed Won670002024-02-012024-04-12
5Stark LogisticsDana BrooksClosed Lost310002024-02-052024-03-18
6Wayne RetailDana BrooksClosed Won540002024-02-112024-03-22
7HooliPriya NairClosed Lost390002024-02-202024-03-30
8Vandelay ImportsMarcus HillClosed Lost120002024-03-012024-03-25

Example Output

sales_repwin_rate_pct
Dana Brooks50
Marcus Hill66.7
Priya Nair33.3

Explanation

Marcus Hill won 2 of 3 closed deals, which is 66.7%, and Priya Nair won 1 of 3, which is 33.3%. Dana Brooks won 1 of 2, which is 50.0%. Deals that are still in progress are not counted as losses.

The example above is a small slice of the data. Your query runs against the full tables.