-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitial_sql_set_up
210 lines (173 loc) · 3.95 KB
/
Initial_sql_set_up
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
--combining the divided july data. this is also done for all the months that have data larger than 100mb
SELECT *
FROM
`case-study-projects-394518.shola_bke_share.2207-book1`
UNION ALL
SELECT *
FROM
`case-study-projects-394518.shola_bke_share.2207-book2`
--combining all the months in summer to form a table
SELECT *
FROM
`case-study-projects-394518.shola_bke_share.2306-book`
UNION ALL
SELECT *
FROM
`case-study-projects-394518.shola_bke_share.2207-book1`
UNION ALL
SELECT *
FROM
`case-study-projects-394518.shola_bke_share.2208-book1`
--converting the data type of start_time and end_time from string to time
SELECT
ride_id,
rideable_type,
started_at,
ended_at,
start_station_name,
start_station_id,
end_station_name,
end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
ride_duration,
ride_date,
ride_month,
ride_year,
SAFE_CAST(start_time AS TIME) AS start_time,
SAFE_CAST (end_time AS TIME) AS end_time,
day_of_week
FROM
`case-study-projects-394518.shola_bke_share.2207-book`
--Uniting all the seasons to form a full year
SELECT
*
FROM
`case-study-projects-394518.Transformed_bk_share.auntumn_months`
UNION DISTINCT
SELECT
*
FROM
`case-study-projects-394518.Transformed_bk_share.summer_months`
UNION DISTINCT
SELECT
*
FROM
`case-study-projects-394518.Transformed_bk_share.spring_months`
UNION DISTINCT
SELECT
*
FROM
`case-study-projects-394518.Transformed_bk_share.winter_months`
--converting the data type of day_of_week from INT to string
--The result was saved as a new table to run analysis on
SELECT
ride_id,
rideable_type,
started_at,
ended_at,
start_station_name,
start_station_id,
end_station_name,
end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
ride_duration,
ride_date,
ride_month,
ride_year,
start_time,
end_time,
CASE
WHEN day_of_week = 1 then 'sunday'
WHEN day_of_week = 2 then 'monday'
WHEN day_of_week = 3 then 'tuesday'
WHEN day_of_week = 4 then 'wednesday'
WHEN day_of_week = 5 then 'thursday'
WHEN day_of_week = 6 then 'friday'
WHEN day_of_week = 7 then 'saturday'
END AS day_of_week
FROM
`case-study-projects-394518.Transformed_bk_share.autumn_months`
--trying to convert the data type of ride_duration from 'time' to 'interval'. But it has to be converted to string first
SELECT ride_id,
rideable_type,
started_at,
ended_at,
start_station_name,
start_station_id,
end_station_name,
end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
CAST (ride_duration AS STRING) AS ride_duration,
ride_date,
ride_month,
ride_year,
start_time,
end_time,
day_of_week,
FROM `case-study-projects-394518.Transformed_bk_share.autumn_month`
--converting the data type from string to interval so calculations can be made
SELECT
ride_id,
rideable_type,
started_at,
ended_at,
start_station_name,
start_station_id,
end_station_name,
end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
CAST (ride_duration AS INTERVAL) AS ride_duration,
ride_date,
ride_month,
ride_year,
start_time,
end_time,
day_of_week,
FROM `case-study-projects-394518.Transformed_bk_share.autumn_sting`
--including season column to the full year table. the table was saved and used for analysis based of seasons
SELECT
ride_id,
rideable_type,
started_at,
ended_at,
start_station_name,
start_station_id,
end_station_name,
end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
ride_duration,
ride_date,
ride_month,
ride_year,
start_time,
end_time,
day_of_week,
CASE
WHEN ride_month BETWEEN 6 and 8 then 'summer'
WHEN ride_month BETWEEN 9 and 11 then 'autumn'
WHEN ride_month BETWEEN 3 and 5 then 'spring'
WHEN ride_month < 3 then 'winter'
WHEN ride_month = 12 then 'winter'
END AS season
FROM
`case-study-projects-394518.Transformed_bk_share.full_year`