logo

Back to questions

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

Easy

CVS Health wants to gain a clearer understanding of its pharmacy sales and the performance of various products.

Write a query to calculate the total drug sales for each manufacturer. Round the answer to the nearest million and report your results in descending order of total sales. In case of any duplicates, sort them alphabetically by the manufacturer name.

Since this data will be displayed on a dashboard viewed by business stakeholders, please format your results as follows: "$36 million".

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

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

Example Output:

manufacturersale
Biogen$4 million
Eli Lilly$3 million

Explanation

The total sales for Biogen is $4 million ($2,041,758.41 + $500,101.61 + $1,084,258.00 = $3,626,118.02) and for Eli Lilly is $3 million ($293,452.54 + $2,521,023.73 = $2,814,476.27).

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

PostgreSQL 14