Skip to content

运算符

算术运算符

运算符
支持的数据类型
说明
++(TINYINT) -> TINYINT
+(SMALLINT) -> SMALLINT
+(INTEGER) -> INTEGER
+(BIGINT) -> BIGINT
+(FLOAT) -> FLOAT
+(DOUBLE) -> DOUBLE
+(UTINYINT) -> UTINYINT
+(USMALLINT) -> USMALLINT
+(UINTEGER) -> UINTEGER
+(UBIGINT) -> UBIGINT
一元运算符,表示正数
--(TINYINT) -> TINYINT
-(SMALLINT) -> SMALLINT
-(INTEGER) -> INTEGER
-(BIGINT) -> BIGINT
-(FLOAT) -> FLOAT
-(DOUBLE) -> DOUBLE
-(UTINYINT) -> UTINYINT
-(USMALLINT) -> USMALLINT
-(UINTEGER) -> UINTEGER
-(UBIGINT) -> UBIGINT
-(INTERVAL) -> INTERVAL
一元运算符,表示负数
++(TINYINT, TINYINT) -> TINYINT
+(SMALLINT, SMALLINT) -> SMALLINT
+(INTEGER, INTEGER) -> INTEGER
+(BIGINT, BIGINT) -> BIGINT
+(FLOAT, FLOAT) -> FLOAT
+(DOUBLE, DOUBLE) -> DOUBLE
+(UTINYINT, UTINYINT) -> UTINYINT
+(USMALLINT, USMALLINT) -> USMALLINT
+(UINTEGER, UINTEGER) -> UINTEGER
+(UBIGINT, UBIGINT) -> UBIGINT
+(INTERVAL, INTERVAL) -> INTERVAL
+(TIMESTAMP, INTERVAL) -> TIMESTAMP
+(INTERVAL, TIMESTAMP) -> TIMESTAMP
+(TIMESTAMP WITH TIME ZONE, INTERVAL) -> TIMESTAMP WITH TIME ZONE
+(INTERVAL, TIMESTAMP WITH TIME ZONE) -> TIMESTAMP WITH TIME ZONE
二元运算符,将两个数值相加。例如,column1 + column2将返回column1和column2相加的结果
--(TINYINT, TINYINT) -> TINYINT
-(SMALLINT, SMALLINT) -> SMALLINT
-(INTEGER, INTEGER) -> INTEGER
-(BIGINT, BIGINT) -> BIGINT
-(FLOAT, FLOAT) -> FLOAT
-(DOUBLE, DOUBLE) -> DOUBLE
-(UTINYINT, UTINYINT) -> UTINYINT
-(USMALLINT, USMALLINT) -> USMALLINT
-(UINTEGER, UINTEGER) -> UINTEGER
-(UBIGINT, UBIGINT) -> UBIGINT
-(TIMESTAMP, TIMESTAMP) -> INTERVAL
-(INTERVAL, INTERVAL) -> INTERVAL
-(TIMESTAMP, INTERVAL) -> TIMESTAMP
-(TIMESTAMP WITH TIME ZONE, INTERVAL) -> TIMESTAMP WITH TIME ZONE
-(TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE) -> INTERVAL
二元运算符,从一个数值中减去另一个数值。例如,column1 - column2将返回column1减去column2的结果
**(TINYINT, TINYINT) -> TINYINT
*(SMALLINT, SMALLINT) -> SMALLINT
*(INTEGER, INTEGER) -> INTEGER
*(BIGINT, BIGINT) -> BIGINT
*(FLOAT, FLOAT) -> FLOAT
*(DOUBLE, DOUBLE) -> DOUBLE
*(UTINYINT, UTINYINT) -> UTINYINT
*(USMALLINT, USMALLINT) -> USMALLINT
*(UINTEGER, UINTEGER) -> UINTEGER
*(UBIGINT, UBIGINT) -> UBIGINT
*(INTERVAL, BIGINT) -> INTERVAL
*(BIGINT, INTERVAL) -> INTERVAL
二元运算符,将两个数值相乘。例如,column1 * column2将返回column1和column2相乘的结果
//(FLOAT, FLOAT) -> FLOAT
/(DOUBLE, DOUBLE) -> DOUBLE
/(INTERVAL, BIGINT) -> INTERVAL
二元运算符,将一个数值除以另一个数值。例如,column1 / column2将返回column1除以column2的结果

TIP

当不同的数据类型做算术运算并且两种类型直接可以转换时,会发生隐式强制转换。例如: -(INTEGER, DOUBLE) -> -(DOUBLE, DOUBLE) -> DOUBLE

比较运算符

比较算符
支持的数据类型
说明
=EVERY用于检查两个值是否相等。示例:WHERE column = value
<> 或 !=EVERY用于检查两个值是否不相等。示例:WHERE column <> value或WHERE column != value
>EVERY用于检查一个值是否大于另一个值。示例:WHERE column > value
<EVERY用于检查一个值是否小于另一个值。示例:WHERE column < value
>=EVERY用于检查一个值是否大于或等于另一个值。示例:WHERE column >= value
<=EVERY用于检查一个值是否小于或等于另一个值。示例:WHERE column <= value
IS NULL / ISNULLEVERY用于检查表达式是否为NULL,如果是则返回true,否则返回false。示例:WHERE column IS NULL
IS NOT NULL / NOTNULLEVERY用于检查表达式是否为NULL,如果是则返回false,否则返回true。示例:WHERE column IS NOT NULL

TIP

我们支持的数据类型目前都支持比较运算。当两种不同类型的数据进行比较时,如果可以进行转换则进行隐式强制转换后比较。例如: =(INTEGER, DOUBLE) -> =(DOUBLE, DOUBLE) -> BOOLEAN

逻辑运算符

逻辑运算符
说明
ANDAND运算符要求所有条件都为真时才返回真。如果一个或多个条件为假,则整个表达式为假。示例:WHERE condition1 AND condition2
OROR运算符要求至少一个条件为真时就返回真。只有所有条件都为假时才返回假。示例:WHERE condition1 OR condition2
NOTNOT运算符用于取反条件的值,如果条件为真,则返回假;如果条件为假,则返回真。示例:WHERE NOT condition

TIP

涉及NULL的逻辑操作符并不总是求值为NULL。例如,NULL和false的计算结果为false, NULL或true的计算结果为true。下面是完整的真值表:

a
b
a AND b
a OR b
NOT a
truetruetruetruefalse
truefalsefalsetruefalse
trueNULLNULLtruefalse
falsefalsefalsefalsetrue
falseNULLfalseNULLtrue
NULLNULLNULLNULLNULL