-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFitness_Data_Cleaning.sql
More file actions
99 lines (71 loc) · 2.96 KB
/
Fitness_Data_Cleaning.sql
File metadata and controls
99 lines (71 loc) · 2.96 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
USE Portfolio_Projects_01
GO
--Bismillah
----Fitness Data Cleaning
----Converting columns to correct data types
----dealing with missing data in original price column
----Extracting values from texts in columns
-----fixing column names
select [Current Price], Cast([Current Price] as Float), try_convert(Decimal (10,2), [Current Price])
from fitness_data
----current price column
update fitness_data
set [Current Price] = try_convert(decimal (10,2), [Current Price])
----original price
update fitness_data
set [Original_Price] = try_convert(decimal (10,2), [Original_Price])
---ratings column
update fitness_data
set [Rating] = try_convert(decimal (10,1), [Rating])
-----populating the original price column
select brand, [Current Price], [original price], [Discount Percentage]
from Fitness_Data
where [Discount Percentage] = 0 and [Current Price] is not null and [original price] is null
update Fitness_Data
set [Original Price]= [Current Price]
where [Discount Percentage] = 0 and [Current Price] is not null and [original price] is null
select brand, [Current Price], [original price], [Discount Percentage]
from Fitness_Data
where [Current Price] is not null and [original price] is not null
select * from Fitness_Data
------extracting values
select [display size], Left([Display size], 4)
from Fitness_Data
where [Display Size] like '% %'
update Fitness_Data
set [Display Size]= Left([Display size], 4)
where [Display Size] like '% %'
-----cleaning the weight column
select [Weight], CASE
when [weight] like '%-%' then left([weight], 7)
when [weight] like '%+%' then left([weight],2)+ '+'
when [weight] like '%<=%' then left([weight],5)
end
from Fitness_Data
where [Weight] like '% %'
update Fitness_Data
set [Weight] = CASE
when [weight] like '%-%' then left([weight], 7)
when [weight] like '%+%' then left([weight],2)+ '+'
when [weight] like '%<=%' then left([weight],5)
end
from Fitness_Data
where [Weight] like '% %'
select distinct [weight]
from Fitness_Data
select * from Fitness_Data
---correcting column names
sp_rename 'dbo.Fitness_data.Current Price','Current_Price', 'COLUMN'
sp_rename 'dbo.Fitness_data.Original Price','Original_Price', 'COLUMN'
sp_rename 'dbo.Fitness_data.Discount Percentage','Discount[%]', 'COLUMN'
sp_rename 'dbo.Fitness_data.Number OF Ratings','Ratings_Count', 'COLUMN'
sp_rename 'dbo.Fitness_data.Model Name','Device_Model', 'COLUMN'
sp_rename 'dbo.Fitness_data.Dial Shape','Device_Shape', 'COLUMN'
sp_rename 'dbo.Fitness_data.Strap Color','Strap_Color', 'COLUMN'
sp_rename 'dbo.Fitness_data.Strap Material','Strap_Material', 'COLUMN'
sp_rename 'dbo.Fitness_data.Battery Life (Days)','Battery_Life[Days]', 'COLUMN'
sp_rename 'dbo.Fitness_data.Display Size','Display_Size["]', 'COLUMN'
sp_rename 'dbo.Fitness_data.Weight','Weight[kg]', 'COLUMN'
select brand, Device_Model
from Fitness_Data
where device_model like '%+%'