-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.5.1_where_exercises.sql
97 lines (77 loc) · 2.01 KB
/
3.5.1_where_exercises.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
85
86
87
88
89
90
91
92
93
94
/* ==================================================
3.5.1 Where Exercises
Ednalyn C. De Dios
2019-02-20
MySQL
Ada Cohort
Codeup Data Science Career Accelerator Program
==================================================
*/
/*
Make sure to use the employees database
*/
USE employees;
SHOW TABLES;
DESCRIBE employees;
/*
Find all employees with first names 'Irena', 'Vidya', or 'Maya'
*/
SELECT * FROM employees
WHERE first_name IN ('Irena', 'Vidya', 'Maya' );
/*
Find all employees whose last name starts with 'E'
*/
SELECT * FROM employees
WHERE last_name LIKE 'E%';
/*
Find all employees hired in the 90s
*/
SELECT * FROM employees
WHERE hire_date BETWEEN '1990/01/01' AND '1999/12/31';
/*
Find all employees born on Christmas
*/
SELECT * FROM employees
WHERE birth_date LIKE '____-12-25';
/*
Find all employees with a 'q' in their last name
*/
SELECT * FROM employees
WHERE last_name LIKE '%q%';
/*
Update your query for 'Irena', 'Vidya', or 'Maya' to use OR instead of IN — 709 rows.
*/
SELECT * FROM employees
WHERE first_name = 'Irena' OR
first_name = 'Vidya' OR
first_name = 'Maya';
/*
Add a condition to the previous query to find everybody with those names who is also male.
*/
SELECT * FROM employees
WHERE (first_name = 'Irena' OR
first_name = 'Vidya' OR
first_name = 'Maya') AND
gender = 'M';
/*
Find all employees whose last name starts or ends with 'E'
*/
SELECT * FROM employees
WHERE last_name LIKE 'E%' OR last_name LIKE '%e';
/*
Duplicate the previous query and update it to find all employees
whose last name starts and ends with 'E'
*/
SELECT * FROM employees
WHERE last_name LIKE 'E%' AND last_name LIKE '%e';
/*
Find all employees hired in the 90s and born on Christmas
*/
SELECT * FROM employees
WHERE birth_date LIKE '____-12-25' AND
(hire_date BETWEEN '1990/01/01' AND '1999/12/31');
/*
Find all employees with a 'q' in their last name but not 'qu'
*/
SELECT * FROM employees
WHERE last_name LIKE '%q%' AND NOT last_name LIKE '%qu%';