-
Notifications
You must be signed in to change notification settings - Fork 2
/
reformat.sql
84 lines (66 loc) · 1.46 KB
/
reformat.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
/* List departments in each row */
select
department
from
staff;
/* List each department name once */
select distinct
department
from
staff;
/* Convert the names of departments to upper case */
select distinct
upper(department)
from
staff;
/* Convert the names of departments to lower case */
select distinct
lower(department)
from
staff;
/* Concatenate two character strings */
select
job_title || '-' || department
from
staff;
/* Use alias to rename concatenated column */
select
job_title || '-' || department title_dept
from
staff;
select distinct
job_title
from
staff;
/* Concatenate two character strings */
select
job_title || '-' || department
from
staff;
/* Use alias to rename concatenated column */
select
job_title || '-' || department title_dept
from
staff;
/* Use trim to remove trailing and leading spaces */
select
trim(' Software Engineer ');
/* Verify length of string with leading and trailing spaces */
select
length(' Software Engineer ');
/* ... and now verify length is shorter when leading and trailing spaces are removed */
select
length(trim(' Software Engineer '));
/* Show all job titles that start wtih Assistant */
select
job_title
from
staff
where
job_title like 'Assistant%'
/* Create a new boolean column indicating if a staff person has the term Assistant
anywhere in their title. */
select
job_title, (job_title like '%Assistant%') is_asst
from
staff;