-
Notifications
You must be signed in to change notification settings - Fork 2
/
reformat_number.sql
56 lines (49 loc) · 1.17 KB
/
reformat_number.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
/* List average salaries by department */
select
department, avg(salary)
from
staff
group by
department;
/* Truncate decimal values toward zero */
select
department, avg(salary), trunc(avg(salary))
from
staff
group by
department;
/* Truncate decimal values toward zero and round up when decimal portion > .5 */
select
department, avg(salary), trunc(avg(salary)), round(avg(salary))
from
staff
group by
department;
/* Ceiling function returns smallest integer larger than it's input value */
select
department, avg(salary), trunc(avg(salary)), ceil(avg(salary))
from
staff
group by
department;
/* Round can be used to round to a number of decimal places */
select
department, avg(salary), round(avg(salary), 2)
from
staff
group by
department;
/* Trunc can be used to truncate to a number of decimal places */
select
department, avg(salary), round(avg(salary), 2), trunc(avg(salary), 2)
from
staff
group by
department;
/* Both round and trunc can be used to truncate to a variable number of decimal places */
select
department, avg(salary), round(avg(salary), 3), trunc(avg(salary), 4)
from
staff
group by
department;