本文参考自:https://blog.csdn.net/qq_23897391/article/details/94715278
Hive—常用数学函数与常见字符串函数
一、常见数学函数
1.四舍五入 round
round(DOUBLE a)
功能:传入DOUBLE类型的参数a,返回对a四舍五入的整数值,但返回的数据类型是DOUBLE,所以会有 .0
hive (app)> select round(2.5);
3.0
hive (app)> select round(2.2);
2.0
round(DOUBLE a,INT d)
功能:传入DOUBLE类型的参数a,INT类型的参数d,返回保留d位小数的DOUBLE型的近似值
hive (app)> select round(2.234,2);
2.23
hive (app)> select round(2.235,2);
2.24
2. 向下取整 floor
floor(DOUBLE a)
功能:传入DOUBLE类型的参数a,返回<=a的最大的BIGINT型整数
hive (app)> select floor(2.2);
2
hive (app)> select floor(2.9);
2
3.向上取整 ceil
ceil(DOUBLE a)
ceiling(DOUBLE a)
功能:传入DOUBLE类型的参数a,返回>=a的最小的BIGINT型整数
hive (app)> select ceil(2.9);
3
hive (app)> select ceil(2.1);
3
hive (app)> select ceiling(2.9);
3
hive (app)> select ceiling(2.1);
3
4.随机数 rand
rand()
rand(INT seed)
功能:每行返回一个DOUBLE型随机数,seed是随机种子,设置seed可以使生成的随机数固定,否则每次生成的随机数是不同的。
hive (app)> select rand();
0.6856