-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathData Analyst Jobs.sql
More file actions
74 lines (55 loc) · 2.01 KB
/
Data Analyst Jobs.sql
File metadata and controls
74 lines (55 loc) · 2.01 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
--Check data
SELECT * FROM analysts
--Analyst Levels in this dataset
SELECT DISTINCT Level FROM analysts
WHERE Level NOT IN ('n/a')
--Group Salary Range by Levels
SELECT Level, STRING_AGG([Salary Range], '|| ') AS Level_Salary_Range FROM analysts
WHERE [Salary Range] NOT IN ('n/a') AND Level NOT IN ('n/a')
GROUP BY Level
ORDER BY Level Desc
--Query Location column to find jobs that are remote
SELECT Location FROM analysts
WHERE Location LIKE 'Remote%'
OR Location LIKE '%Remote'
OR Location LIKE '%Remote%'
--Create a new column base off Loaction (Onsite/Remote)
SELECT Location,
(CASE
WHEN Location LIKE 'Remote%' OR Location LIKE '%Remote' OR Location LIKE '%Remote%' THEN 'Remote'
ELSE 'Onsite'
END) as Onsite_Remote
FROM analysts
ALTER TABLE analysts
ADD Onsite_Remote VARCHAR(255)
UPDATE analysts
SET Onsite_Remote =
CASE
WHEN Location LIKE 'Remote%' OR Location LIKE '%Remote' OR Location LIKE '%Remote%' THEN 'Remote'
ELSE 'Onsite'
END
SELECT * FROM analysts
-- Remove NonAlphaCharacters from necessary columns
--First, create a function that removes all NonAlphaCharacter
Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin
Declare @KeepValues as varchar(50)
Set @KeepValues = '%[^a-z, ]%'
While PatIndex(@KeepValues, @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')
Return @Temp
End
--Call the function with the Columns to initiate cleaning
Select dbo.RemoveNonAlphaCharacters([Required Skills]) AS [Required Skills (Cleaned)], [Required Skills] FROM analysts --Required Skills
Select dbo.RemoveNonAlphaCharacters(Benefits) AS [Job Benefits (Cleaned)], Benefits FROM analysts --Benefits
-- Permanent the Cleaning in the Columns
UPDATE analysts
SET [Required Skills] = dbo.RemoveNonAlphaCharacters([Required Skills])
UPDATE analysts
SET Benefits = dbo.RemoveNonAlphaCharacters(Benefits)
--Clean the Salary Range Column
UPDATE analysts
SET [Salary Range] = REPLACE([Salary Range], ' *', '')
SELECT * FROM analysts