-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviwing the data.sql
More file actions
102 lines (91 loc) · 2.12 KB
/
reviwing the data.sql
File metadata and controls
102 lines (91 loc) · 2.12 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
/* checks if the results is Clean but the biological column is > 0.01 */
SELECT
*
FROM
well_pollution
WHERE
results = 'clean'
AND biological > 0.01;
/*Case 1a: Update descriptions that mistakenly mention
`Clean Bacteria: E. coli` to `Bacteria: E. coli` */
SELECT
*
FROM well_pollution
WHERE description
LIKE
'%Bacteria: E. coli';
UPDATE md_water_services.well_pollution
SET description = 'Bacteria: E. coli'
WHERE
description = '%Bacteria: E. coli';
/*Case 1b: Update the descriptions that mistakenly mention
`Clean Bacteria: Giardia Lamblia` to `Bacteria: Giardia Lamblia */
SELECT
*
FROM
well_pollution
WHERE
description
LIKE
'%Bacteria: Giardia Lamblia';
UPDATE
md_water_services.well_pollution
SET
description = '%Bacteria: Giardia Lamblia'
WHERE
description = '%Bacteria: Giardia Lamblia';
SELECT * FROM well_pollution;
/* Case 2: Update the `result` to `Contaminated: Biological` where
`biological` is greater than 0.01 plus current results is `Clean` */
UPDATE
md_water_services.well_pollution
SET
results = 'Contaminated: Biological'
WHERE
biological > 0.01
AND
results = 'clean';
CREATE TABLE
md_water_services.well_pollution_copy
AS (
SELECT
*
FROM
md_water_services.well_pollution
);
SELECT * FROM md_water_services.well_pollution_copy;
SELECT DISTINCT description
FROM well_pollution;
/*check if our errors are fixed */
SELECT
*
FROM
well_pollution_copy
WHERE
description LIKE "Clean_%"
OR (results = "Clean" AND biological > 0.01);
DROP TABLE
md_water_services.well_pollution_copy;
/* check for fraud */
SELECT *
FROM employee
WHERE position = 'Field Surveyor'
AND (phone_number LIKE '%86%' OR phone_number LIKE '%11%')
AND (
SUBSTRING_INDEX(employee_name, ' ', -1) LIKE 'A%' OR
SUBSTRING_INDEX(employee_name, ' ', -1) LIKE 'M%'
);
SELECT
ws.source_id,
wp.results,
ws.type_of_water_source
FROM well_pollution wp
JOIN
water_source ws
ON
wp.source_id = ws.source_id;
/* count the number of rows */
SELECT COUNT(*) AS row_count
FROM well_pollution
WHERE description IN ('Parasite: Cryptosporidium', 'biologically contaminated')
OR (results = 'Clean' AND biological > 0.01);