Cloud

floor

The floor() returns a number rounded down that is less than or equal to the specified argument.

Syntax

The syntax for the floor() function in Redpanda SQL is:

FLOOR(x)

The floor() function requires one argument:

x: A positive or a negative decimal number (or an expression that evaluates to a decimal number).

Examples

Round down a positive decimal value

This example demonstrates how the floor() function rounds down a positive decimal value:

SELECT FLOOR(345.6765467);

This returns 345 as it is the closest value smaller than the argument.

+------+
| f    |
+------+
| 345  |
+------+

Round down a negative decimal value

This example demonstrates how the floor() function rounds down a negative decimal value:

SELECT FLOOR(-0.987657);

The result is the nearest integer smaller than or equal to the specified argument.

+-------+
| f     |
+-------+
| -1    |
+-------+

Use the floor() function with a table

This example demonstrates how to use the floor() function with a table to round down values in a specific column:

  1. Create a new table called FloorRecords with double-precision values:

    CREATE TABLE FloorRecords (numbers float);
    INSERT INTO FloorRecords VALUES (3.987), (4.325), (-0.76), (-22.57);
  2. Retrieve the table with its values:

    SELECT * ,FLOOR(numbers) AS Floorvalue FROM FloorRecords;
  3. Result:

    • numbers, the column with the initial double-precision values.

    • FloorValue, the column with the rounded-down values.

      +------------+---------------+
      | numbers    | Floorvalue    |
      +------------+---------------+
      | 3.987      | 3             |
      | 4.325      | 4             |
      | -0.76      | -1            |
      | -22.57     | -23           |
      +------------+---------------+