logo

Back to questions

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

Easy

CVS Health is analyzing its pharmacy sales data, and how well different products are selling in the market. Each drug is exclusively manufactured by a single manufacturer.

Write a query to identify the manufacturers associated with the drugs that resulted in losses for CVS Health and calculate the total amount of losses incurred.

Output the manufacturer's name, the number of drugs associated with losses, and the total losses in absolute value. Display the results sorted in descending order with the highest losses displayed at the top.

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

Table:

Column NameType
product_idinteger
units_soldinteger
total_salesdecimal
cogsdecimal
manufacturervarchar
drugvarchar

Example Input:

product_idunits_soldtotal_salescogsmanufacturerdrug
156895143130097.003427421.73BiogenAcyclovir
252223312753546.002974975.36AbbVieLamivudine and Zidovudine
50904842521023.732742445.90Eli LillyDermasorb TA Complete Kit
98110746813188.82140422.87BiogenMedi-Chord

Example Output:

manufacturerdrug_counttotal_loss
Biogen1297324.73
AbbVie1221429.36
Eli Lilly1221422.17

Explanation:

The first three rows indicate that some drugs resulted in losses. Among these, Biogen had the highest losses, followed by AbbVie and Eli Lilly. However, the Medi-Chord drug manufactured by Biogen reported a profit and was excluded from the result.

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

PostgreSQL 14