Amazing! Now let's summarize what we've learned in this part:
- Computations using floating point numbers are not always exact. Use the
money data types for all money columns and whenever precision matters.
- Dividing two integers is integer division, which is not always accurate. Use
CAST(column AS TYPE) or the
:: operator to avoid it.
- Avoid division by zero.
We've learned some useful functions:
- The modulo operation (
x % y) returns the remainder of
ROUND(x, p) rounds
x to the nearest integer or to the specified number of decimal digits (
CEILING(x) rounds up to the nearest integer value.
FLOOR(x) rounds down to the nearest integer value.
ABS(x) returns the absolute value of
TRUNC(x, p) – removes decimal digits given in
p from the number
TRUNC(x) removes all decimal digits.
:: operator and the
CAST() function convert data types.
The queries we've written so far have been fairly simple. Let's test your knowledge with some more advanced exercises.