-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfetch_first.sql
55 lines (50 loc) · 943 Bytes
/
fetch_first.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
/* Review a few columns from the staff table */
select
last_name, job_title, salary
from
staff;
/* Use order by and fetch first to limit the number of rows returned */
select
last_name, job_title, salary
from
staff
order by
salary desc
fetch first
10 rows only;
/* Select a simple column - aggregrate combination */
select
company_division, count(*)
from
staff_div_reg
group by
company_division;
/* Select with a sort order */
select
company_division, count(*)
from
staff_div_reg
group by
company_division
order by
count(*);
/* Set the sort order to descending */
select
company_division, count(*)
from
staff_div_reg
group by
company_division
order by
count(*) desc;
/* Use fetch first with order by to select top 5 divisions by staff count */
select
company_division, count(*)
from
staff_div_reg
group by
company_division
order by
count(*) desc
fetch first
5 rows only;