Created
May 28, 2024 03:23
-
-
Save lfy79001/c27b516837bf108a7dbe604f78715aca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
A.state, | |
drug_name, | |
total_claim_count, | |
day_supply, | |
ROUND(total_cost_millions) AS total_cost_millions | |
FROM ( | |
SELECT | |
generic_name AS drug_name, | |
nppes_provider_state AS state, | |
ROUND(SUM(total_claim_count)) AS total_claim_count, | |
ROUND(SUM(total_day_supply)) AS day_supply, | |
ROUND(SUM(total_drug_cost)) / 1e6 AS total_cost_millions | |
FROM | |
`bigquery-public-data.cms_medicare.part_d_prescriber_2014` | |
GROUP BY | |
state, | |
drug_name) A | |
INNER JOIN ( | |
SELECT | |
state, | |
MAX(total_claim_count) AS max_total_claim_count | |
FROM ( | |
SELECT | |
nppes_provider_state AS state, | |
ROUND(SUM(total_claim_count)) AS total_claim_count | |
FROM | |
`bigquery-public-data.cms_medicare.part_d_prescriber_2014` | |
GROUP BY | |
state, | |
generic_name) | |
GROUP BY | |
state) B | |
ON | |
A.state = B.state | |
AND A.total_claim_count = B.max_total_claim_count | |
ORDER BY | |
A.total_claim_count DESC | |
LIMIT | |
5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment