-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovid_19.sql
More file actions
125 lines (82 loc) · 3.14 KB
/
Copy pathCovid_19.sql
File metadata and controls
125 lines (82 loc) · 3.14 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
select * FROM covid_dataset;
-- BASIC SQL
-- How many total patient records are present in the table?--
SELECT count(*) FROM covid_dataset;
-- How many patients tested COVID positive? --
SELECT count(*) as covid_positive FROM covid_dataset
WHERE Has_Covid='Yes';
-- Retrieve all patients with fever greater than 101°F.
SELECT * FROM covid_dataset
WHERE Fever >101;
-- List distinct cities represented in the dataset.
SELECT DISTINCT(City) from covid_dataset;
-- Count the number of patients for each gender.
SELECT Gender,COUNT(*) as total from covid_dataset
Group by Gender;
-- AGGREGATION & GROUP BY
-- Find the average fever for COVID-positive and COVID-negative patients.
SELECT Has_covid,avg(Fever) from covid_dataset
group by Has_covid;
-- Count COVID-positive cases by gender.
SELECT Gender,count(Has_Covid) from covid_dataset
group by Gender;
-- Show the number of patients in each city.
SELECT City,count(*) from covid_dataset
group by City;
-- Find the maximum and minimum fever recorded in the dataset.
SELECT max(Fever),min(Fever) from covid_dataset;
-- Calculate the average age of COVID-positive patients.
SELECT avg(age) as avg_age_positive from covid_dataset
where Has_Covid='Yes';
-- HEALTHCARE-FOCUSED ANALYTICS
-- How many COVID-positive patients have a strong cough?
SELECT COUNT(*) as total_strong_covid FROM covid_dataset
where Has_Covid='Yes' and Cough='Strong';
-- What percentage of COVID-positive patients have fever ≥ 101°F?
SELECT
COUNT(CASE WHEN Fever >= 101 THEN 1 END) * 100.0 / COUNT(*) AS percentage_high_fever
FROM covid_dataset
WHERE Has_Covid = 'Yes';
-- Compare the average fever between patients with mild cough and strong cough.
SELECT Cough,AVG(FEVER) from covid_dataset
group by Cough;
-- Identify cities with more than 50 COVID-positive cases.
Select City,COUNT(
CASE WHEN Has_Covid='Yes' THEN 1 END) positive_cases from covid_dataset
group by City
Having positive_cases>110;
SELECT
FLOOR(Age / 10) * 10 AS age_group,
COUNT(*) AS covid_cases
FROM covid_dataset
WHERE Has_Covid = 'Yes'
GROUP BY FLOOR(Age / 10)
ORDER BY covid_cases DESC
LIMIT 1;
-- DECISION SUPPORT / LOGIC
-- Identify high-risk patients defined as age ≥ 60, fever ≥ 101°F, and strong cough.
select * from covid_dataset
where Age>=60 and Fever>=101 and Cough='Strong';
-- Count how many high-risk patients actually tested COVID positive.
select count(*) from covid_dataset
where Age>=60 and Fever>=101 and Cough='Strong';
-- Compare COVID positivity rates between high-risk and low-risk patients.
Select
Case
when Age >= 60 AND Fever >= 101 AND Cough = 'Strong'
then 'High Risk'
else 'Low Risk'
end as risk_group,
count(case when Has_Covid = 'Yes' then 1 end) * 100.0 / count(*) AS positivity_rate
from covid_dataset
group by risk_group;
-- Create a risk label (High / Low) based on fever and cough severity.
Select *,
Case
When Fever >= 101 AND Cough = 'Strong' THEN 'High Risk'
else'Low Risk'
end as risk_label
from covid_dataset;
-- Find false-negative cases where patients were high risk but COVID negative.
SELECT * FROM covid_dataset
WHERE Age>=60 and Fever>101 and Cough='Strong' and Has_Covid='No';