导航

  • ​​hive outline​​
  • ​​hive 数学函数​​
  • ​​取整函数: round​​
  • ​​指定精度取整函数: round​​
  • ​​向下取整函数: floor​​
  • ​​向上取整函数: ceil​​
  • ​​取随机数函数: rand​​
  • ​​二进制函数: bin​​
  • ​​进制转换函数: conv​​
  • ​​绝对值函数: abs​​

hive outline

​​链接​​

hive 数学函数

取整函数: round

返回double类型的整数值部分 (遵循四舍五入)

select round(3.1415926);

指定精度取整函数: round

​语法:​​ round(double a, int d) 返回d位小数

select round(3.1415926,4);

向下取整函数: floor

select floor(3.1415926);
-- 输出 3

select floor(-3.1415926);
-- 输出 -4

向上取整函数: ceil

取随机数函数: rand

rand 每次执行都不一样 返回一个0到1范围内的随机数

select rand();

​语法:​​ rand(int seed) 得到一个稳定的随机数序列

select rand(2);

二进制函数: bin

​语法:​​ bin(BIGINT a)

select bin(18);
-- 输出 10010

进制转换函数: conv

​语法:​​ conv(BIGINT num/STRING num, int from_base, int to_base)

将数字 num 或者字符串 num 从 from_base 进制转换到 to_base 进制

select conv(17,10,16); -- 将17从10进制转换为16进制
-- 输出 11

绝对值函数: abs

select abs(-3.9);