The INTERVAL SQL Function in MySQL and MariaDB - Position in list |
|
| INTERVAL | Syntax: | INTERVAL(%, %) | Return value: | INTEGER | Function type: | Comparison function | |
| | The INTERVAL() function returns the position of the last argument from a list that is less or equal than the first argument in the list or NULL.
The function returns -1 if the first argument is NULL.
All arguments in the list are treated as integers.
For this function to work correctly, the elements of the list must have increasing values. Consecutive values can be the same. If not, the function returns 0. | SQL Examples for the INTERVAL function |
|
SELECT INTERVAL(5, 1, 2, 3, 4, 5, 6);
SELECT INTERVAL(5, 1, 2, 3, 4, 5, 5);
SELECT INTERVAL(50, 10, 20, 30, 40, 50, 60);
SELECT INTERVAL(50, 10, 20, 30, 40, 50, null);
SELECT INTERVAL(50, null, null, 30, 40, 50, 60);
SELECT INTERVAL(50, 50, 50, 50, 50, 50, 50);
SELECT INTERVAL(50, 70, 80, 30, 40, 50, 60);
SELECT INTERVAL(50, null, null, null, null);
SELECT INTERVAL(null, 10, 20, 30, 40, 50, 60);
|
|
INTERVAL(5, 1, 2, 3, 4, 5, 6) |
int(2) |
5 |
|
|
INTERVAL(5, 1, 2, 3, 4, 5, 5) |
int(2) |
6 |
|
|
INTERVAL(50, 10, 20, 30, 40, 50, 60) |
int(2) |
5 |
|
|
INTERVAL(50, 10, 20, 30, 40, 50, null) |
int(2) |
6 |
|
|
INTERVAL(50, null, null, 30, 40, 50, 60) |
int(2) |
5 |
|
|
INTERVAL(50, 50, 50, 50, 50, 50, 50) |
int(2) |
6 |
|
|
INTERVAL(50, 70, 80, 30, 40, 50, 60) |
int(2) |
0 |
|
|
INTERVAL(50, null, null, null, null) |
int(2) |
4 |
|
|
INTERVAL(null, 10, 20, 30, 40, 50, 60) |
int(2) |
-1 |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the INTERVAL() function in MySQL and MariaDB databases | In MySQL and MariaDB the INTERVAL() function is used to determine the position of the last argument from a list of values, whose value is less than or equal to the first value in the list. All values are converted to whole numbers. Table column names or other expressions can also be used as parameters. The values in the list should be in ascending order starting from position two, but they can also be the same. | | Further MySQL und MariaDB SQL Comparison functions | |
| | More information about the INTERVAL SQL function: and |
|
|
|
|