-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaningData.sql
64 lines (52 loc) · 1.62 KB
/
cleaningData.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
----------------------------------------------------------------------------------------
--Populate Team data
select a.name, a.team, b.name, b.team, ISNULL(a.team,b.team)
from athlete_events a
join athlete_events b
on a.name = b.name
and a.[ID] = b.[ID]
where a.team is null;
Update a
set Team = ISNULL(a.Team,b.Team)
from athlete_events a
join athlete_events b
on a.name = b.name
and a.[ID]=b.[ID]
where a.Team is null;
select name, team
from athlete_events
where team is null;
----------------------------------------------------------------------------------------
--Breaking out Games into Individual Columns (Year, Season)
select Games
from athlete_events;
select Games,
SUBSTRING(Games, 1, CHARINDEX(',',Games) -1) as Year,
SUBSTRING(Games, CHARINDEX(',',Games) +1, len(Games)) as Season
from athlete_events;
Alter Table athlete_events
Add y Nvarchar(255);
Update athlete_events
set y = SUBSTRING(Games, 1, CHARINDEX(',',Games) -1);
Alter Table athlete_events
Add Season Nvarchar(255);
Update athlete_events
set Season = SUBSTRING(Games, CHARINDEX(',',Games) +1, len(Games));
select * from athlete_events;
----------------------------------------------------------------------------------------
--Change Y and N to Yes and No in "Medal" field
select Distinct(Medal), count(Medal)
from athlete_events
group by Medal
order by 2
select Medal
, case when Medal= 'Y' then 'Yes'
when Medal = 'N' then 'No'
else Medal
end
from athlete_events
Update athlete_events
SET Medal = case when Medal= 'Y' then 'Yes'
when Medal = 'N' then 'No'
else Medal
end