-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL Function Notes.sql
76 lines (64 loc) · 1.8 KB
/
SQL Function Notes.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
SELECT
concat("Employee #", emp_no, " is " , first_name, " ", last_name) # " " is the literal value of space
FROM employees
LIMIT 10;
SELECT
concat(first_name, ' ', last_name)
FROM employees
LIMIT 10;
SELECT
concat(first_name, ' ', last_name) AS full_name
FROM employees
LIMIT 10;
# this returns boolean checking to see whether or not the first 10 names begin with the letters a - f. If they do, true
SELECT
first_name,
first_name REGEXP "^[a-f].*" # first name starts with a - f. Qualifying statement; the '^' means 'starts with'
FROM employees
LIMIT 10;
# this shows ten people whose check to see if a-f first name is true
SELECT
first_name,
first_name REGEXP "^[a-f].*" # first name starts with a - f. Qualifying statement; the '^' means 'starts with'
FROM employees
WHERE first_name REGEXP "^[a-f].*"
LIMIT 10;
# Pulls the first letter from the first name
SELECT
first_name,
substr(first_name, 1, 1)
FROM employees
LIMIT 10;
SELECT
first_name,
substr(first_name, 1, 1)
FROM employees
LIMIT 10;
SELECT
first_name,
substr(first_name, 1, 1)
FROM employees
WHERE substr(first_name, 1, 1) IN ('A', 'B', 'C', 'D', 'E', 'F')
LIMIT 10;
SELECT
first_name,
substr(first_name, 3, 3), # first number is the letter place in the name we want, second num is how many we want after
substr(first_name, 3, 1)
FROM employees
LIMIT 10;
# first several characters from the left and from the right side of the string
SELECT
first_name,
LEFT(first_name, 3),
RIGHT(first_name, 3)
FROM employees
LIMIT 10;
# takes the first three letters from the first name, the last three from the right of the first name,
# and the last three letters from the last name - look at the funtion names
SELECT
first_name,
LEFT(first_name, 3),
RIGHT(first_name, 3),
LEFT(RIGHT(concat(first_name, ' ', last_name), 3), 4)
FROM employees
LIMIT 10;