-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatistics.sql
More file actions
45 lines (39 loc) · 1.07 KB
/
statistics.sql
File metadata and controls
45 lines (39 loc) · 1.07 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
/* Show the first 10 rows of the staff table */
select * from staff limit 10;
/* Sum the total amount of salary paid to staff */
select sum(salary) from staff;
/* Sum the total amount of salary paid to staff by department */
select
department, sum(salary)
from
staff
group by
department;
/* Sum the total, and average (or mean) amount of salary paid to staff by department */
select
department, sum(salary), avg(salary)
from
staff
group by
department;
/* Sum the total, average (or mean) and variance of salary paid to staff by department */
select
department, sum(salary), avg(salary), var_pop(salary)
from
staff
group by
department;
/* Sum the total, average (or mean), variance and standard deviation of salary paid to staff by department */
select
department, sum(salary), avg(salary), var_pop(salary), stddev_pop(salary)
from
staff
group by
department;
/* Use round function to round to 2 decimal places */
select
department, sum(salary), avg(salary), round(var_pop(salary),2), round(stddev_pop(salary),2)
from
staff
group by
department;