mysql数学函数之greatest,least用法
2018-03-08 11:00
513 查看
语法
GREATEST(value1,value2,…)With two or more arguments, returns the largest (maximum-valued) argument. The arguments are compared using the same rules as for LEAST().
使用两个或更多参数,返回最大(最大值)参数。 参数使用与LEAST()相同的规则进行比较。
LEAST(value1,value2,…)
With two or more arguments, returns the smallest (minimum-valued) argument. The arguments are compared using the following rules:
o If any argument is NULL, the result is NULL. No comparison is needed.
o If all arguments are integer-valued, they are compared as integers.
o If at least one argument is double precision, they are compared as double-precision values. Otherwise, if at least one argument is a DECIMAL value, they are compared as DECIMAL values.
o If the arguments comprise a mix of numbers and strings, they are compared as numbers.
o If any argument is a nonbinary (character) string, the arguments are compared as nonbinary strings.
o In all other cases, the arguments are compared as binary strings.
The return type of LEAST() is the aggregated type of the comparison argument types.
使用两个或更多参数,返回最小(最小值)参数。 使用以下规则比较参数:
o如果有任一参数为NULL,则结果为NULL。 不需要比较。
o如果所有参数都是整数值,则将它们作为整数进行比较。
o如果至少有一个参数是双精度,则将它们作为双精度值进行比较。 否则,如果至少有一个参数是DECIMAL值,则将它们作为DECIMAL值进行比较。
o如果参数包含数字和字符串的混合,则将它们作为数字进行比较。
o如果有任一参数是非二进制(字符)字符串,则参数将作为非二进制字符串进行比较。
o在所有其他情况下,参数将作为二进制字符串进行比较。
LEAST()的返回类型是比较参数类型的聚合类型。
实例
SELECT greatest(3,1,5,9,2,NULL); # null SELECT greatest(3,1,5,9,2,6); # 9 SELECT greatest(3,1,5,9,2,6.0); # 9.0 SELECT greatest(3,1,5,9,2,'6'); # 9 SELECT least(3,1,5,9,2,NULL); # null SELECT least(3,1,5,9,2,6); # 1 SELECT least(3,1,5,9,2,6.0); # 1.0 SELECT least(3,1,5,9,2,'6'); # 1
相关文章推荐
- mysql数学函数之sign,sqrt用法
- mysql数学函数之pi,abs,mod用法
- MySQL数学函数之div的用法
- mysql数学函数之truncate用法
- mysql数学函数之ceil,floor用法
- mysql数学函数
- mysql时间函数之hour,minute,second用法
- MySQL 学习<四> MySQL函数简介(数学函数、字符串函数、日期和时间函数)
- mysql中find_in_set()函数的使用及in()用法详解
- MySQL自定义函数用法详解
- oracle 函数 WMSYS.WM_CONCAT 与对应 mysql 函数GROUP_CONCAT的用法
- mysql 数学函数
- MySQL学习笔记18:数学函数
- oracle 函数 WMSYS.WM_CONCAT 的用法 与 mysql 函数GROUP_CONCAT的用法
- web报表工具FineReport常用函数的用法总结(数学和三角函数)
- Mysql字符串截取函数SUBSTRING的用法说明
- MySQL的行转列、列转行、连接字符串 concat、concat_ws、group_concat函数用法
- oracle 函数 WMSYS.WM_CONCAT 的用法 与 mysql 函数GROUP_CONCAT的用法
- 整理了下MySQL内置函数表,包括字符串函数、数学函数和日期时间函数
- oracle 函数 WMSYS.WM_CONCAT 的用法 与 mysql 函数GROUP_CONCAT的用法