-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_by_exercises.sql
79 lines (65 loc) · 1.69 KB
/
order_by_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
USE employees;
--Modify your first query to order by first name.
--The first result should be Irena Reutenauer
--and the last result should be Vidya Simmen.
SELECT *
FROM employees
WHERE first_name
IN ('Irena', 'Vidya', 'Maya')
ORDER BY first_name;
--Update the query to order by first name and then last name.
--The first result should now be Irena Acton and the last should be Vidya Zweizig.
SELECT *
FROM employees
WHERE first_name
IN ('Irena', 'Vidya', 'Maya')
ORDER BY first_name, last_name;
--Change the order by clause so that you order by last name before first name.
--Your first result should still be Irena Acton but now the last result should be Maya Zyda.
SELECT *
FROM employees
WHERE first_name
IN ('Irena', 'Vidya', 'Maya')
ORDER BY last_name, first_name;
--Update your queries for employees with 'E' in their last name to sort the results
--by their employee number. Your results should not change!
SELECT *
FROM employees
WHERE last_name
LIKE 'E%'
ORDER BY emp_no;
SELECT *
FROM employees
WHERE last_name
LIKE 'e%'
OR last_name
LIKE '%e'
ORDER BY emp_no;
SELECT *
FROM employees
WHERE last_name
LIKE 'e%'
AND last_name
LIKE '%e'
ORDER BY emp_no;
--Now reverse the sort order for both queries.
SELECT *
FROM employees
WHERE first_name
IN ('Irena', 'Vidya', 'Maya')
ORDER BY last_name, first_name;
SELECT *
FROM employees
WHERE last_name
LIKE 'E%'
ORDER BY emp_no DESC;
--Change the query for employees hired in the 90s and born on Christmas
--such that the first result is the oldest employee who was hired last.
--It should be Khun Bernini.
SELECT *
FROM employees
WHERE hire_date
LIKE "199%-%-%"
AND birth_date
LIKE "%-12-25"
ORDER BY birth_date, hire_date DESC;