Numbers and rounding in SQL
Rounding is a decision, so make it an explicit one.
SELECT
price,
ROUND(price) AS nearest,
CEIL(price) AS rounded_up,
FLOOR(price) AS rounded_down,
ABS(price - 100) AS distance_from_100,
price % 10 AS remainder,
ROUND(SQRT(price), 4) AS root,
POWER(price, 2) AS squared
FROM products;
How it works
ROUNDtakes decimals;CEILandFLOORalways go one way.%is the remainder operator;MODis the function spelling.ABS,SQRTandPOWERdo what their names say.
Keywords and builtins used here
ABSASFROMSELECT
The run, in numbers
- Lines
- 10
- Characters to type
- 232
- Tokens
- 62
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 39 seconds.
Step 5 of 7 in Expressions, step 20 of 24 in Analytics & reporting.