logo

Back to questions

Pharmacy Analytics (Part 1) [CVS Health SQL Interview Question]

Easy

CVS Health is trying to better understand its pharmacy sales, and how well different products are selling. Each drug can only be produced by one manufacturer.

Write a query to find the top 3 most profitable drugs sold, and how much profit they made. Assume that there are no ties in the profits. Display the result from the highest to the lowest total profit.

Definition:

  • stands for Cost of Goods Sold which is the direct cost associated with producing the drug.
  • Total Profit = Total Sales - Cost of Goods Sold

If you like this question, try out Pharmacy Analytics (Part 2)!

Table:

Column NameType
product_idinteger
units_soldinteger
total_salesdecimal
cogsdecimal
manufacturervarchar
drugvarchar

Example Input:

product_idunits_soldtotal_salescogsmanufacturerdrug
937410293452.54208876.01Eli LillyZyprexa
3494698600997.19521182.16AstraZenecaSurmontil
6177023500101.61419174.97BiogenVaricose Relief
13614481410842581006447.73BiogenBurkhart

Example Output:

drugtotal_profit
Zyprexa84576.53
Varicose Relief80926.64
Surmontil79815.03

Explanation:

Zyprexa made the most profit (of $84,576.53) followed by Varicose Relief (of $80,926.64) and Surmontil (of $79,815.3).

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

PostgreSQL 14