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 a integer division. Use
CAST(column AS TYPE) to avoid it.
- Avoid division by zero. For now ...
We've also learned some useful functions:
x%y – it returns the reminder of division of
round (x) or
round(x,p) – rounds up the number to the integer or to specified precision (
ceil(x) – rounds up to a nearest integer value
floor(x) – rounds down to a nearest integer value
trunc(x,p) – always round towards zero to interger value or to specified precision (
abs(x) – returns a absolute value of
sqrt(x) – returns a square root of
The queries we've written so far were fairly simple. Let's test your knowledge with more advanced examples.