-
Notifications
You must be signed in to change notification settings - Fork 2
/
count_min_max.sql
67 lines (53 loc) · 1.01 KB
/
count_min_max.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
/* Start with a simple select statement */
select * from staff;
/* Show the number of rows in the table staff */
select count(*) from staff;
/* Show the number of staff members by gender */
select
count(*)
from
staff
group by
gender;
/* Now, show the number of staff member by gender and include the name of the gender */
select
gender, count(*)
from
staff
group by
gender;
/* Show the number of staff members in each department */
select
department, count(*)
from
staff
group by
department;
/* Show the maximum salary of all staff member */
select
max(salary)
from
staff;
select
min(salary)
from
staff;
/* Show the minimum salary of all staff member */
select
min(salary), max(salary)
from
staff;
/* Show the minimum and maximum salary in each department */
select
department, min(salary), max(salary)
from
staff
group by
department;
/* Show the minimum and maximum salary by gender */
select
gender, min(salary), max(salary)
from
staff
group by
gender;