-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhere_exercises.sql
More file actions
96 lines (80 loc) · 3.18 KB
/
where_exercises.sql
File metadata and controls
96 lines (80 loc) · 3.18 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
-- WHERE exercises
USE employees;
DESCRIBE employees;
SELECT * FROM employees LIMIT 10;
-- Find all current or previous employees with first names 'Irena', 'Vidya', or 'Maya' using IN. Enter a comment with the number of records returned.
-- A: 709
SELECT count(*)
FROM employees
WHERE first_name IN ('Irena', 'Vidya', 'Maya');
-- Find all current or previous employees with first names 'Irena', 'Vidya', or 'Maya', as in Q2, but use OR instead of IN. Enter a comment with the number of records returned. Does it match number of rows from Q2?
-- A: 709
SELECT count(*)
FROM employees
WHERE first_name = 'Irena'
OR first_name = 'Vidya'
OR first_name = 'Maya';
-- Find all current or previous employees with first names 'Irena', 'Vidya', or 'Maya', using OR, and who is male. Enter a comment with the number of records returned.
-- A: 441
SELECT count(*)
FROM employees
WHERE (first_name = 'Irena' OR first_name = 'Vidya' OR first_name = 'Maya')
AND gender = 'M';
-- Find all current or previous employees whose last name starts with 'E'. Enter a comment with the number of employees whose last name starts with E.
-- A: 7330
SELECT count(*)
FROM employees
WHERE last_name LIKE 'E%';
-- Find all current or previous employees whose last name starts or ends with 'E'. Enter a comment with the number of employees whose last name starts or ends with E.
-- A: 30723
SELECT count(*)
FROM employees
WHERE last_name LIKE 'E%'
OR last_name LIKE '%e';
-- How many employees have a last name that ends with E, but does not start with E?
-- A: 23393
SELECT count(*)
FROM employees
WHERE (last_name LIKE '%e')
AND (last_name NOT LIKE 'E%');
-- Find all current or previous employees employees whose last name starts and ends with 'E'. Enter a comment with the number of employees whose last name starts and ends with E.
-- A: 899
SELECT count(*)
FROM employees
WHERE last_name LIKE 'E%'
AND last_name LIKE '%e';
SELECT count(*)
FROM employees
WHERE last_name LIKE 'E%e';
-- How many employees' last names end with E, regardless of whether they start with E?
-- A: 24292
SELECT count(*)
FROM employees
WHERE last_name LIKE '%e';
-- Find all current or previous employees hired in the 90s. Enter a comment with the number of employees returned.
-- A: 135214
SELECT count(*)
FROM employees
WHERE hire_date LIKE '199%';
-- Find all current or previous employees born on Christmas. Enter a comment with the number of employees returned.
-- A: 842
SELECT count(*)
FROM employees
WHERE birth_date LIKE '%12-25';
-- Find all current or previous employees hired in the 90s and born on Christmas. Enter a comment with the number of employees returned.
-- A: 362
SELECT count(*)
FROM employees
WHERE hire_date LIKE '199%'
AND birth_date LIKE '%12-25';
-- Find all current or previous employees with a 'q' in their last name. Enter a comment with the number of records returned.
-- A: 1873
SELECT count(*)
FROM employees
WHERE last_name LIKE '%q%';
-- Find all current or previous employees with a 'q' in their last name but not 'qu'. How many employees are found?
-- A: 547
SELECT count(*)
FROM employees
WHERE last_name LIKE '%q%'
AND last_name NOT LIKE '%qu%';