-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery1(Covid Data Visualization).sql
More file actions
210 lines (88 loc) 路 5.75 KB
/
Copy pathSQLQuery1(Covid Data Visualization).sql
File metadata and controls
210 lines (88 loc) 路 5.75 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
-- To Fetch & make the temporary table we use (#temp) syntax!
with #temp_datadriven as (select continent,total_cases,population from coviddeath where continent is
not null )
select * from #temp_datadriven
-- To Fetch all the details of a particular Table!
select * from coviddeath
select * from covidvaccinations
--To join the two tables on the basis of some common data we use join command!
select * from coviddeath join covidvaccinations on coviddeath.location=covidvaccinations.location
-- join two tables with the help of Alias!
select * from coviddeath dea join covidvaccinations vac on dea.location=vac.location
-- By using where Clause!
select * from coviddeath dea join covidvaccinations vac on dea.location=vac.location
where new_cases is not null
-- To fetch a particular data of a Table!
select positive_rate,tests_per_case,tests_units,total_tests,people_vaccinated,people_fully_vaccinated
from covidvaccinations where total_tests is not null
-- Data manipulation with the help of MAX,MIN,AVG!
select max(positive_rate)as newcolumn,tests_per_case,tests_units,total_tests,people_vaccinated,
people_fully_vaccinated
from covidvaccinations where total_tests is not null group by positive_rate,tests_per_case,
tests_units,total_tests,people_vaccinated,people_fully_vaccinated order by 3,4
select positive_rate ,tests_per_case,tests_units,total_tests,min(people_vaccinated) as minvaccinations,
people_fully_vaccinated
from covidvaccinations where total_tests is not null group by positive_rate,tests_per_case,
tests_units,total_tests,people_vaccinated,people_fully_vaccinated order by 3,4
select positive_rate,tests_per_case,tests_units,total_tests,people_vaccinated,
avg(cast(people_fully_vaccinated as int)) as avgvaccinations
from covidvaccinations where total_tests is not null group by positive_rate,tests_per_case,
tests_units,total_tests,people_vaccinated,people_fully_vaccinated order by 3,4
--To Fetch the Data & and Make the CTE(Common Table Expressions)!
with cte_coviddata as (
select max(positive_rate)as newcolumn,tests_per_case,tests_units,total_tests,people_vaccinated,
people_fully_vaccinated
from covidvaccinations where total_tests is not null group by positive_rate,tests_per_case,
tests_units,total_tests,people_vaccinated,people_fully_vaccinated
)
select * from cte_coviddata
--How to Perform Different Joins!(full join,right join,inner join,right outer join,left join, left outer join)!
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath full join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath right join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath inner join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath right outer join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath left join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
select hosp_patients,hosp_patients,weekly_icu_admissions_per_million
,total_cases_per_million,total_deaths_per_million
from coviddeath left outer join covidvaccinations on coviddeath.iso_code=covidvaccinations.iso_code where
hosp_patients is not null and weekly_hosp_admissions_per_million is not null
-- how to use UNION and UNION ALL!
select continent,reproduction_rate,population from coviddeath union select
location,continent,total_tests from covidvaccinations where continent is not null
order by 2,3
select continent,reproduction_rate,population from coviddeath union all select
location,continent,total_tests from covidvaccinations where continent is not null
order by 1,2
--Use of <>,<,>,=,<=,>=!
select * from covidvaccinations where location = 'greece'
select * from covidvaccinations where continent <> 'asia'
select * from covidvaccinations where new_tests_smoothed <1100
select * from covidvaccinations where new_vaccinations_smoothed_per_million >2573
select * from covidvaccinations where new_vaccinations_smoothed_per_million >=13553
select * from covidvaccinations where new_vaccinations_smoothed_per_million <=553
-- Use of like keyword(clause)!
select * from covidvaccinations where iso_code like 'grc'
-- how to use stored Procedure!
create procedure test as select * from coviddeath
exec test
create procedure vaccinations as select * from covidvaccinations
exec vaccinations
--TO View the percentage of total deaths as per population!
select continent,total_deaths,population ,(total_deaths/population)*100 as
percentageofdeath from coviddeath where total_deaths is not null
order by total_deaths desc