Top Profitable Drugs
Meta 👶 Easy SQL
Beginner Mode

Objective

Write a SQL query to identify the top 3 most profitable drugs from pharmacy sales data.

Table Schema:

  • pharmacy_sales
Column Type Description
product_id INTEGER Unique identifier for each product
drug_name VARCHAR Name of the drug
units_sold INTEGER Number of units sold
total_sales DECIMAL Total sales revenue
cogs DECIMAL Cost of goods sold

Task Requirements:

  • Calculate total profit for each drug (total_sales - cogs)
  • Sum profits across all records for each drug
  • Select only the top 3 most profitable drugs
  • Sort results by profit in descending order

Output columns: drug_name, total_profit

Examples

Example 1:

Input:

pharmacy_sales
cogsdrug_nameproduct_idtotal_salesunits_sold
2000Aspirin15000100
3000Ibuprofen27500150
3500Paracetamol38000200
2500Amoxicillin4600080

Output:
drug_nametotal_profit
Ibuprofen4500
Paracetamol4500
Amoxicillin3500
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →