-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pharmacy Analytics (Part 1) [CVS Health SQL Interview Question]
41 lines (33 loc) · 1.43 KB
/
Pharmacy Analytics (Part 1) [CVS Health SQL Interview Question]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
select drug,(total_sales - cogs) as total_profit
from pharmacy_sales
ORDER BY total_profit DESC
limit 3
--------------
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:
cogs 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)!
pharmacy_sales Table:
Column Name Type
product_id integer
units_sold integer
total_sales decimal
cogs decimal
manufacturer varchar
drug varchar
pharmacy_sales Example Input:
product_id units_sold total_sales cogs manufacturer drug
9 37410 293452.54 208876.01 Eli Lilly Zyprexa
34 94698 600997.19 521182.16 AstraZeneca Surmontil
61 77023 500101.61 419174.97 Biogen Varicose Relief
136 144814 1084258 1006447.73 Biogen Burkhart
Example Output:
drug total_profit
Zyprexa 84576.53
Varicose Relief 80926.64
Surmontil 79815.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!