Annual Revenue by Manufacturer
Meta 👶 Easy SQL
Beginner Mode

Objective

Write a SQL query to calculate the total sales revenue for each manufacturer from the pharmacy sales data.

Table Schema:

  • pharmacy_sales
Column Type Description
product_id INTEGER Unique identifier for each product
manufacturer VARCHAR Name of the drug manufacturer
drug VARCHAR Name of the drug
units_sold INTEGER Number of units sold
total_sales DECIMAL Total sales revenue in dollars
cogs DECIMAL Cost of goods sold
sale_date DATE Date of the sale

Task Requirements:

  • Calculate total sales for each manufacturer
  • Round the total to the nearest million
  • Format as "$X million" (e.g., "$105 million")
  • Sort by total sales descending, then alphabetically by manufacturer for ties

Output columns: manufacturer, sale

Examples

Example 1:

Input:

pharmacy_sales
cogsdrugmanufacturerproduct_idsale_datetotal_salesunits_sold
30000000LipitorPfizer12024-01-15500000001000
25000000ViagraPfizer22024-02-2055000000800
40000000KeytrudaMerck32024-03-1075000000500
20000000StelaraJohnson & Johnson42024-04-0545000000600

Output:
manufacturersale
Pfizer$105 million
Merck$75 million
Johnson & Johnson$45 million
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 →