Amazing! OK, let's summarize what we've learned today. We know the following principles:
- Computations in floating point numbers are not always exact. Use decimal numbers for all money columns and when precision matters.
- Dividing two integers is an integer division. Use
CAST(column AS TYPE) to avoid errors.
- Avoid division by zero. For now ...
We've also learned some useful functions:
x%y – returns the remainder of division of
round(x,p) – rounds the number to an integer or to a specified precision (
ceil(x) – rounds up to the nearest integer value.
floor(x) – rounds down to the nearest integer value.
trunc(x,p) – always round towards zero to an interger value or to a specified precision (
abs(x) – returns the absolute value of
sqrt(x) – returns the square root of
The queries we've written so far were fairly simple. Let's test your knowledge with more advanced examples.