Annual Revenue by Manufacturer
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:
Output:
Input:
| pharmacy_sales | ||||||
|---|---|---|---|---|---|---|
| cogs | drug | manufacturer | product_id | sale_date | total_sales | units_sold |
| 30000000 | Lipitor | Pfizer | 1 | 2024-01-15 | 50000000 | 1000 |
| 25000000 | Viagra | Pfizer | 2 | 2024-02-20 | 55000000 | 800 |
| 40000000 | Keytruda | Merck | 3 | 2024-03-10 | 75000000 | 500 |
| 20000000 | Stelara | Johnson & Johnson | 4 | 2024-04-05 | 45000000 | 600 |
| manufacturer | sale |
|---|---|
| Pfizer | $105 million |
| Merck | $75 million |
| Johnson & Johnson | $45 million |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Meta