Show the top 10 companies and their most common...
Created on May 6, 2025
Prompt
Show the top 10 companies and their most common routes of administration
Chart
Query Results
Query Results
SQL Query:
WITH TopApplicants AS (
-- Step 1: Find the top 10 applicants by total product count
SELECT
applicant_full_name,
COUNT(*) AS total_product_count
FROM orange_book_products
WHERE applicant_full_name IS NOT NULL
GROUP BY 1
ORDER BY total_product_count DESC
LIMIT 10
),
ApplicantRouteCounts AS (
-- Step 2: For the top applicants, count the occurrences of each route
SELECT
ta.applicant_full_name,
p.route,
COUNT(p.id) AS route_product_count
FROM orange_book_products p
JOIN TopApplicants ta ON p.applicant_full_name = ta.applicant_full_name
WHERE p.route IS NOT NULL
GROUP BY 1, 2
),
RankedRoutes AS (
-- Step 3: Rank the routes for each applicant based on their count
SELECT
applicant_full_name,
route,
route_product_count,
-- Assign a rank to each route within an applicant, 1 being the most common
ROW_NUMBER() OVER (PARTITION BY applicant_full_name ORDER BY route_product_count DESC, route) as rn
FROM ApplicantRouteCounts
)
-- Step 4: Select the most common route (rank 1) for each top applicant
-- and include their total product count for ordering
SELECT
rr.applicant_full_name AS applicant_name,
ta.total_product_count,
rr.route AS most_common_route,
rr.route_product_count AS count_of_most_common_route
FROM RankedRoutes rr
JOIN TopApplicants ta ON rr.applicant_full_name = ta.applicant_full_name
WHERE rr.rn = 1
ORDER BY ta.total_product_count DESC -- Order the final result by the applicant's total product count
LIMIT 20;Results:
| applicant_name | total_product_count | most_common_route | count_of_most_common_route |
|---|---|---|---|
| WATSON LABORATORIES INC | 1221 | TABLET;ORAL | 749 |
| AUROBINDO PHARMA LTD | 967 | TABLET;ORAL | 555 |
| CHARTWELL RX SCIENCES LLC | 794 | TABLET;ORAL | 528 |
| HOSPIRA INC | 790 | INJECTABLE;INJECTION | 666 |
| HIKMA PHARMACEUTICALS USA INC | 760 | INJECTABLE;INJECTION | 326 |
| SANDOZ INC | 742 | TABLET;ORAL | 297 |
| TEVA PHARMACEUTICALS USA INC | 714 | TABLET;ORAL | 408 |
| ZYDUS PHARMACEUTICALS USA INC | 692 | TABLET;ORAL | 357 |
| SUN PHARMACEUTICAL INDUSTRIES LTD | 646 | TABLET;ORAL | 266 |
| APOTEX INC | 569 | TABLET;ORAL | 279 |
Chart Configuration
{
"grid": {
"left": "3%",
"right": "4%",
"bottom": "3%",
"containLabel": true
},
"title": {
"text": "Total Product Count by Applicant"
},
"xAxis": {
"data": [
"WATSON LABORATORIES INC",
"AUROBINDO PHARMA LTD",
"CHARTWELL RX SCIENCES LLC",
"HOSPIRA INC",
"HIKMA PHARMACEUTICALS USA INC",
"SANDOZ INC",
"TEVA PHARMACEUTICALS USA INC",
"ZYDUS PHARMACEUTICALS USA INC",
"SUN PHARMACEUTICAL INDUSTRIES LTD",
"APOTEX INC"
],
"type": "category",
"axisLabel": {
"rotate": 45,
"interval": 0
}
},
"yAxis": {
"type": "value"
},
"legend": {
"data": [
"Total Product Count"
]
},
"series": [
{
"data": [
1221,
967,
794,
790,
760,
742,
714,
692,
646,
569
],
"name": "Total Product Count",
"type": "bar"
}
],
"tooltip": {
"trigger": "axis",
"axisPointer": {
"type": "shadow"
}
}
}