Back to questions

Pharmacy Analytics (Part 4) CVS Health SQL Interview Question

Pharmacy Analytics (Part 4)

CVS Health SQL Interview Question

CVS Health is trying to better understand its pharmacy sales, and how well different drugs are selling.

Write a query to find the top 2 drugs sold, in terms of units sold, for each manufacturer. List your results in alphabetical order by manufacturer.

Table:

Column NameType
product_idinteger
units_soldinteger
total_salesdecimal
cogsdecimal
manufacturervarchar
drugvarchar

Example Input:

product_idunits_soldtotal_salescogsmanufacturerdrug
941323622041758.411373721.70BiogenUP and UP
937410293452.54208876.01Eli LillyZyprexa
50904842521023.732742445.9Eli LillyDermasorb
6177023500101.61419174.97BiogenVaricose Relief
1361448141084258.001006447.73BiogenBurkhart
1091186961433109.50263857.96Eli LillyTizanidine Hydrochloride

Example Output:

manufacturertop_drugs
BiogenBurkhart
BiogenUP and UP
Eli LillyTizanidine Hydrochloride
Eli LillyTA Complete Kit

Explanation

Biogen sold 144,814 units of Burkhart drug (ranked 1) followed by the second highest with 132,362 units of UP and UP drug (ranked 2).

Eli Lilly sold 118,696 units of Tizanidine Hydrochloride drug (ranked 1) followed by the second highest with 90,484 units of TA Complete Kit drug (ranked 2).

The dataset you are querying against may have different input & output - this is just an example!

Input

Output