©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The INTERVAL SQL Function in MySQL and MariaDB - Position in list

INTERVALSyntax:INTERVAL(%, %)
Return value:INTEGER
Function type:Comparison function
Function Description

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

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, nullnull, 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, nullnullnullnull);
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: Download

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.
INET_NTOAINSERTINSTRINTERVALIS_IPV4IS_IPV6IS_UUID

Further MySQL und MariaDB SQL Comparison functions

COALESCECOALESCE(%, %)
More about COALESCE Function

DECODE_ORACLEDECODE_ORACLE()
More about DECODE_ORACLE Function

GREATESTGREATEST(%, %)
More about GREATEST Function

IFIF(Expression, Value1, Value2)
More about IF Function

LEASTLEAST(%, %)
More about LEAST Function

STRCMPSTRCMP(String 1, String 2)
More about STRCMP Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the INTERVAL SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer