Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Data Science
emergency-calls
Commits
a8abd1e9
Commit
a8abd1e9
authored
Jun 24, 2016
by
Ahsan Ali Khoja
Browse files
Commented the psql queries
parent
183c5ce9
Changes
1
Hide whitespace changes
Inline
Side-by-side
911_history.sql
View file @
a8abd1e9
/* Converts Positive longitudes to Negative. */
UPDATE
calls
SET
longitude
=
(
-
1
*
longitude
)
WHERE
longitude
>
0
;
/* Updating our_complaint by collapsing the 10 code s*/
UPDATE
calls
SET
our_complaint
=
'10-11'
WHERE
complaint
LIKE
'10-11%'
;
UPDATE
calls
SET
our_complaint
=
'10-10'
WHERE
complaint
=
'10-10'
;
UPDATE
calls
SET
our_complaint
=
''
WHERE
complaint
=
''
;
...
...
@@ -15,31 +16,30 @@ UPDATE calls SET our_complaint = '10-58' WHERE complaint LIKE '10-58%';
UPDATE
calls
SET
our_complaint
=
'10-59'
WHERE
complaint
LIKE
'10-59%'
;
UPDATE
calls
SET
our_complaint
=
'10-70'
WHERE
complaint
LIKE
'10-70%'
;
UPDATE
calls
SET
our_complaint
=
'10-97'
WHERE
complaint
LIKE
'10-97%'
;
/* Craigles did something here */
CREATE
TEMPORARY
TABLE
temptable
(
call
character
(
20
),
abb
character
(
5
),
name
character
(
50
));
\
copy
temptable
(
call
,
abb
,
name
)
from
'/home/datascience/departmentsdispatched.csv'
with
(
format
csv
);
/* Craigles did something here */
\
copy
temptable
(
call
,
abb
,
name
)
from
'/cluster/home/datascience/departmentsdispatched.csv'
with
(
format
csv
);
CREATE
TEMPORARY
TABLE
temptable
(
call
character
(
20
),
abb
character
(
5
),
name
character
(
50
));
\
copy
temptable
(
call
,
abb
,
name
)
from
'/cluster/home/datascience/departmentsdispatched.csv'
with
(
format
csv
);
insert
into
test
(
agency_abbrev
,
agency_name
)
select
abb
,
name
from
temptable
;
/* Craigles did something here */
DROP
TABLE
temptable
;
\
copy
call_details
FROM
'/cluster/home/datascience/departmentsdispatched.csv'
WITH
DELIMITER
(
','
)
CSV
;
\
copy
call_details
FROM
'/cluster/home/datascience/departmentsdispatched.csv'
WITH
DELIMITER
(
','
)
CSV
;
\
copy
call_details
FROM
'/cluster/home/datascience/departmentsdispatched.csv'
CSV
;
/* Make another copy of the table calls*/
create
table
test
as
select
*
from
calls
;
alter
table
test
add
our_city
char
(
20
);
/* Updating our_city column which has correct city, or county when the city is not in Wayne County(or State in case of Ohio). */
update
test
set
city
=
'Richmond'
where
city
=
'RCHMOND'
;
update
test
set
our_city
=
'Richmond'
where
lower
(
city
)
like
'%ichm%'
;
update
test
set
our_city
=
'Richmond'
where
lower
(
city
)
=
'rchmond'
;
update
test
set
our_city
=
'Randolph county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
like
'rando%'
;
update
test
set
our_city
=
'Randolph county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
like
'rando%'
;
-- out_of_jurisdiction is set to True for cities out of Wayne County
update
test
set
our_city
=
'Rush county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
=
'rushville'
;
update
test
set
our_city
=
'Randolph county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
=
'ridgeville'
;
update
test
set
our_city
=
'Greens Fork'
where
lower
(
city
)
=
'greens%'
;
update
test
set
our_city
=
'Greens Fork'
where
lower
(
city
)
like
'greens%'
;
update
test
set
our_city
=
'Fayette county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
like
'fayette%'
;
update
test
set
our_city
=
'Fayette county'
,
out_of_jurisdiction
=
true
where
lower
(
city
)
like
'connersville%'
;
...
...
@@ -74,6 +74,5 @@ update test set our_city = 'Muncie' where lower(city) = 'sweetwater';
update
test
set
our_city
=
'Centerville'
where
lower
(
city
)
=
'cnet'
;
update
test
set
our_city
=
'Economy'
where
lower
(
city
)
=
'econd'
;
update
test
set
our_city
=
'Richmond'
where
lower
(
address
)
=
'18 n 22nd st'
;
\
copy
(
select
(
address
||
','
||
our_city
)
as
c_add
from
test
where
latitude
is
null
and
complaint_category
<>
'o'
)
to
'lat_long_find.csv'
with
csv
delimiter
','
;
/* Make a csv file for the addresses which do not have latitudes and are not to be ommitted. This file is then used by the QGIS for geocoding. */
\
copy
(
select
address
,
our_city
from
test
where
latitude
is
null
and
complaint_category
<>
'o'
)
to
'lat_long_find.csv'
with
csv
delimiter
','
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment