-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssign1_DDL_DML.sql
More file actions
85 lines (64 loc) · 3.6 KB
/
Assign1_DDL_DML.sql
File metadata and controls
85 lines (64 loc) · 3.6 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
use mydb;
show tables;
SELECT * FROM HOMEFILESCENTER.TOURISM;
select * from homefilescenter.tourism_accomodate;
select * from homefilescenter.graduation_info;
select count(*) from homefilescenter.tourism_visitor;
select count(*) from homefilescenter.tourism_accomodate;
select * from homefilescenter.crime_index;
select max(num_of_visitors) from homefilescenter.tourism_visitor;
select count(*) from homefilescenter.tourism_visitor where num_of_visitors=0;
select distinct(region) from homefilescenter.crime_index;
-- --Cape Breton Region, Nova Scotia, municipal
-- --Halifax Metropolitain Area, Nova Scotia, municipal
-- --Annapolis County, Nova Scotia, Royal Canadian Mounted Police, rural
select * from homefilescenter.graduation_info;
-- Cape Breton-Victoria Regional School Board
-- Halifax Regional School Board
-- Annapolis Valley Regional School Board
create table homefilescenter.graduation_info_update as(
select school_board,grade_9_graduation_year,num_of_graduating_students,grade_9_enrolment,graduation_rate,
case when school_board="Cape Breton-Victoria Regional School Board" then "Cape Breton"
when school_board="Halifax Regional School Board" then "Halifax"
when school_board="Annapolis Valley Regional School Board" then "Annapolis"
end as region_name
from homefilescenter.graduation_info);
SELECT COUNT(*) FROM HOMEFILESCENTER.GRADUATION_INFO;
SELECT * FROM homefilescenter.graduation_info;
describe homefilescenter.graduation_info;
select * from homefilescenter.crime_index_update;
create table homefilescenter.crime_index_update as(
select region,year,total_crime_severity_index,
case when region="Halifax Metropolitain Area, Nova Scotia, municipal" then "Halifax"
when region="Cape Breton Region, Nova Scotia, municipal" then "Cape Breton"
when region="Annapolis County, Nova Scotia, Royal Canadian Mounted Police, rural" then "Annapolis"
end as region_name
from homefilescenter.crime_index);
select a.*,b.total_crime_severity_index from
homefilescenter.graduation_info_update a, homefilescenter.crime_index_update b
where a.region_name=b.region_name
and a.year=b.year;
select * from homefilescenter.graduation_info_update;
select year,avg(NUM_OF_VISITORS) as average_num_of_visitors FROM homefilescenter.TOURISM_VISITOR
group by year
order by year;
select year,avg(occupancy_rate) as average_occupancy_rate FROM homefilescenter.tourism_accomodate
group by year
order by year;
create table homefilescenter.tourism_visitor_update
as(select year,avg(NUM_OF_VISITORS) as average_num_of_visitors FROM homefilescenter.TOURISM_VISITOR
group by year
order by year);
create table homefilescenter.tourism_accomodate_update
as(select year,avg(occupancy_rate) as average_occupancy_rate FROM homefilescenter.tourism_accomodate
group by year
order by year);
select * from homefilescenter.tourism_accomodate_update;
select a.*,b.average_occupancy_rate from
homefilescenter.tourism_visitor_update a,homefilescenter.tourism_accomodate_update b
where a.year=b.year;
SELECT * FROM homefilescenter.crime_index_update;
SELECT * FROM homefilescenter.crime_index;
select * from homefilescenter.graduation_info_update;
select * from homefilescenter.tourism_visitor_update;
SELECT * FROM homefilescenter.tourism_accomodate_update;