-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit_exercises.sql
More file actions
73 lines (64 loc) · 1.65 KB
/
Copy pathlimit_exercises.sql
File metadata and controls
73 lines (64 loc) · 1.65 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
Show Databases;
Use employees;
describe employees;
/* Question 2
List the first 10 distinct last name sorted in descending order.
*/
Select distinct
last_name
From
employees
ORDER BY
last_name DESC
Limit 10;
# The ten names are: Zykh, Zyda, Zwicker, Zweizig, Zumaque, Zultner, Zucker, Zuberek, Zschoche, Zongker
/* Question 3
Find all previous or current employees hired in the 90s and born on Christmas.
Find the first 5 employees hired in the 90's by sorting by hire date and limiting your results to the first 5 records.
Write a comment in your code that lists the five names of the employees returned.
*/
SELECT
first_name,
last_name,
birth_date,
hire_date
FROM
employees
WHERE
hire_date like '199%'
AND birth_date LIKE '%-12-25'
ORDER BY
hire_date ASC
LIMIT 5;
/* The 5 names are:
Alselm Cappello,
Utz Mandell,
Bouchung Schreiter,
Baocai Kushner,
Petter Stroustrup
*/
/* Question 4
Try to think of your results as batches, sets, or pages.
The first five results are your first page.
The five after that would be your second page, etc.
Update the query to find the tenth page of results.
*/
SELECT
first_name,
last_name,
birth_date,
hire_date
FROM
employees
WHERE
hire_date like '199%'
AND birth_date LIKE '%-12-25'
ORDER BY
hire_date ASC
LIMIT 5 Offset 45;
#Question 5
#LIMIT and OFFSET can be used to create multiple pages of data.
# What is the relationship between OFFSET (number of results to skip),
# LIMIT (number of results per page),
# and the page number?
# ANSWER: The offset number divided by the limit plus one the page number and the limit is the amount of text or data on the specific page.