-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimit_exercises.sql
41 lines (36 loc) · 968 Bytes
/
limit_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
USE employees;
SELECT DISTINCT title
FROM titles;
# List the first 10 distinct last name sorted
# in descending order.
SELECT DISTINCT last_name
FROM employees
ORDER BY last_name DESC
LIMIT 10 OFFSET 0;
# Create a query to get the top 5
# salaries and display just the employees
# number from the salaries table.
# The employee number results should be:
# 43624
# 43624
# 254466
# 47978
# 253939
SELECT emp_no, salary
FROM salaries
ORDER BY salary DESC
LIMIT 5 OFFSET 0;
# 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
# previous query to find the tenth page of results. The employee number results should
# 36219
# 254466
# 492164
# 66793
# 492164
# starts with every 5 * 10 = 50... but - 5 because first page is 0? so 5 * 9?
#offset = pages * limit - limit 10 * 5 - 5
SELECT emp_no
FROM salaries
ORDER BY salary DESC
LIMIT 5 OFFSET 45;