-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataMiningQueries.sql
80 lines (67 loc) · 2.46 KB
/
DataMiningQueries.sql
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
\! rm -f dataminingOutfile.txt
tee dataminingOutfile.txt;
SELECT '-----------------------------------------------------------------------' as '';
SELECT 'Crime Datamining Queries' AS '';
-- Crime per capita for each minor category
SELECT minorCategory, COUNT(generalCrimeID)*100000/(SELECT SUM(population) FROM LSOA) AS crimesPerCapita
FROM GeneralCrime
GROUP BY minorCategory
ORDER BY crimesPerCapita DESC;
-- Crime per capita for each year
SELECT year, COUNT(generalCrimeID)*100000/(SELECT SUM(population) FROM LSOA) AS crimesPerCapita
FROM GeneralCrime
WHERE year > 2007 AND year < 2017
GROUP BY year
ORDER BY year;
-- Crime per capita for each borough
SELECT borough, numCrimes*100000/pop AS crimesPerCapita
FROM (
SELECT COUNT(generalCrimeID) AS numCrimes, borough
FROM LSOA
INNER JOIN GeneralCrime USING (lsoa)
GROUP BY borough
) AS t1
INNER JOIN (
SELECT borough, SUM(population) AS pop
FROM LSOA
GROUP BY borough
) AS t2 USING(borough)
ORDER BY crimesPerCapita DESC;
-- Specific Data to identify trends
SELECT borough, year, minorCategory, numCrimes*100000/pop AS crimesPerCapita
FROM (
SELECT COUNT(generalCrimeID) AS numCrimes, minorCategory, borough, year
FROM LSOA
INNER JOIN GeneralCrime USING (lsoa)
GROUP BY borough, year, minorCategory
ORDER BY borough, year, minorCategory
) AS t1
INNER JOIN (
SELECT borough, SUM(population) AS pop
FROM LSOA
GROUP BY borough
) AS t2 USING(borough);
SELECT '-----------------------------------------------------------------------' as '';
SELECT 'Stop And Search Datamining Queries' AS '';
-- Search ratio per gender
SELECT gender, COUNT(*)/(SELECT COUNT(*) FROM SearchProfile) AS searchRatio
FROM SearchProfile
GROUP BY gender;
-- Search ratio per officer defined ethnicity
SELECT officerDefinedEthnicity, COUNT(*)/(SELECT COUNT(*) FROM SearchProfile) AS searchRatio
FROM SearchProfile
GROUP BY officerDefinedEthnicity;
-- Search ratio per self defined ethnicity
SELECT selfDefinedEthnicity, COUNT(*)/(SELECT COUNT(*) FROM SearchProfile) AS searchRatio
FROM SearchProfile
GROUP BY selfDefinedEthnicity;
-- Search ratio per age range
SELECT ageRange, COUNT(*)/(SELECT COUNT(*) FROM SearchProfile) AS searchRatio
FROM SearchProfile
GROUP BY ageRange;
-- Specific Data to identify trends
SELECT gender, officerDefinedEthnicity, ageRange, COUNT(*)/(SELECT COUNT(*) FROM SearchProfile) AS searchRatio
FROM SearchProfile
GROUP BY gender,officerDefinedEthnicity, ageRange
ORDER BY searchRatio DESC;
notee;