-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion_3.sql
More file actions
35 lines (35 loc) · 987 Bytes
/
Question_3.sql
File metadata and controls
35 lines (35 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
SELECT
E.State,
E.Per_Capita_Income,
RANK() OVER (ORDER BY E.Per_Capita_Income DESC) AS Income_Rank,
C.Disease_AgeAdj_Prev,
RANK() OVER (ORDER BY C.Disease_AgeAdj_Prev DESC) AS COPD_Prevalence_Rank
FROM
(SELECT
State,
Estimate AS Per_Capita_Income
FROM
us_economy_data
WHERE
`Label (Grouping)` = 'Per capita income (dollars)'
) AS E
JOIN
(SELECT
LocationDesc AS State,
AVG(DataValue) AS Disease_AgeAdj_Prev
FROM
us_chronic_data_cleaned
WHERE
Topic LIKE '%Chronic Obstructive Pulmonary Disease%'
AND Question LIKE '%Chronic obstructive pulmonary disease among adults%'
AND DataValueType LIKE '%Age-adjusted Prevalence%'
AND Stratification1 = 'Overall'
AND LocationDesc != 'United States'
GROUP BY
LocationDesc
) AS C
ON E.State = C.State
WHERE
E.State != 'Puerto Rico'
ORDER BY
COPD_Prevalence_Rank