-
Notifications
You must be signed in to change notification settings - Fork 0
/
anime.sql
156 lines (135 loc) · 2.62 KB
/
anime.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
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
/*
Cleaning Data in SQL Queries
*/
SELECT
*
FROM
anime;
-------------------------------------------------------------------------------------
-- Renaming 'DVD s' to 'DVD'
SELECT DISTINCT
(Type)
FROM
anime;
SELECT
Name, Type
FROM
anime
WHERE
Type = 'DVD S';
UPDATE anime
SET
Type = 'DVD'
WHERE
Type = 'DVD s';
-- Rounding the Rating Column to one decimal place
SELECT
*, ROUND(Rating, 1)
FROM
anime;
UPDATE anime
SET
Rating = ROUND(Rating, 1);
-- Changing Double coma to single coma in Tags Column
SELECT
REPLACE(Tags, ',,', ',')
FROM
anime
WHERE
Tags LIKE '%,,%';
UPDATE anime
SET
Tags = REPLACE(Tags, ',,', ',')
WHERE
Tags LIKE '%,,%';
-- Delecting Columns 'Japanese_name', 'Release_season', 'End_year'
-- Deleting records where the 'Rating' is below 3.5 and 'Type' is Music
Alter table anime
drop column Japanese_name;
Alter table anime
drop column Release_season;
Alter table anime
drop column End_year;
DELETE FROM anime
WHERE
Rating > 3.5;
DELETE FROM anime
WHERE
Type = 'Music';
-- Adding a New column 'Based_on'
-- Breaking out Tags into a New Column 'Based_on'
SELECT
Tags,
SUBSTR(Tags, LOCATE('Based', Tags)),
REPLACE(Tags,
SUBSTR(Tags, LOCATE('Based', Tags)),
'')
FROM
anime;
Alter table anime
add Based_on Text;
UPDATE anime
SET
Based_on = SUBSTR(Tags, LOCATE('Based', Tags));
UPDATE anime
SET
Tags = REPLACE(Tags,
SUBSTR(Tags, LOCATE('Based', Tags)),
'');
-- Handling Null Values
SELECT
Name,
IFNULL(Content_Warning, 'No Warning'),
Content_Warning IS NULL,
LENGTH(Content_Warning)
FROM
anime;
UPDATE anime
SET
Content_Warning = IFNULL(Content_Warning, 'No Warning');
UPDATE anime
SET
Content_Warning = REPLACE(Content_warning,
'No Warning',
'Safe');
UPDATE anime
SET
Episodes = IFNULL(Episodes, 'On going')
WHERE
Type = 'TV';
UPDATE anime
SET
Episodes = IFNULL(Episodes, 'On going')
WHERE
Type = 'TV Sp';
UPDATE anime
SET
Episodes = IFNULL(Episodes, 'On going')
WHERE
Type = 'Dvd';
UPDATE anime
SET
Episodes = IFNULL(Episodes, 1)
WHERE
Type = 'Movie';
UPDATE anime
SET
Based_on = NULL
WHERE
LENGTH(Based_on) = 0;
-- Trimimg values in 'Type' column
SELECT DISTINCT
(Type), LENGTH(Type)
FROM
anime;
UPDATE anime
SET
Type = RTRIM(Type);
-- Removing unwanted strings from column Tags
SELECT
Tags, SUBSTR(Tags, 1, LENGTH(Tags) - 2)
FROM
anime;
UPDATE anime
SET
Tags = SUBSTR(Tags, 1, LENGTH(Tags) - 2);