栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hive函数大全

hive函数大全

一、数学函数

1.1 基本运算

1.round(double a[,d])         保留d位小数,默认保留整数

2.bround(double a[,d])         保留d为小数,财务计数法(保留位的数字是单数时,后面是500则进一位,双数时不进位)

select bround(2.1651,2); =>2.17
select bround(2.1550,2); =>2.16
select bround(2.1650,2); =>2.16
select bround(2.1551,2); =>2.16

3.floor(double a)                                   向下取整
4.ceil(double a)                                    向上取整
5.abs(double a)                                    绝对值
6.positive(int/double a)                        本身
7.negative(int/double a)                       相反数
8.sign(double/int a)                              判断正负函数
9.pi()                                                    常量 Π
10.rand()                                              随机数0-1
11.exp(double) | e()                             自然对数

1.2 对数运算

12.log(double base ,double a)              log 以base为低的对数
13. ln(double a)

1.3 数学运算

14.pow(double a,double b)            a^b
15.sqrt(double a)                            a^(1/2)
16.cbrl(double a)                             a^(1/3)
17.factorial(int a)                             阶乘 a最大为20
18.pmod(a,b)                                  取余a%b
19.greatest(int a...b)                       取最大值,只能列举
20.least(int a...b)                             取最小值,只能列举

1.4 进制转化
21.bin(int a)                                            十进制转为二进制
22.hex(int a) || unhex(string a)                十进制转为十六进制
23.conv(int a,int from_pas,int to_pas)      a从from_pas进制转为to_pas进制

1.3 三角函数
24.sin(double/decmal a)||cos() tan()        三角函数
25.asin() || acos() || atan()                反三角函数
26.degrees(double a)                        弧度转角度
27.radains(double a)                        角度转弧度

1.4 位运算
28.shiftleft(int a,int b)                    a按位左移b
29.shiftright(int a,int b)                  a按位右移b
30.shiftleftunsigned(int a,int b)           (有符号)a按位左移b

二:时间函数

  2.1 获取当前的函数

        1.unix_timestamp([string date][,string format])   //获取当前时间 || 指定时间的 指定格式的时间戳

select unix_timestamp();  ==>1644806355

        2.current_timestamp()                       //获取当前时间

select current_timestamp()   ==2022-02-14 14:05:51.959

         3.current_date()                                //获取当前日期

select current_date()    ==>2022-02-14

   2.2 时间<=>时间戳

        4.from_unixtime(bigint timestamp,string format)   // 按指定格式解析时间戳

select from_unixtime(1644819052,"yyyy-MM-dd hh-mm-ss:SS")   ==>2022-02-14 06-10-52:00

        5.to_date(string timestamp)                //时间日期->日期

select to_date("2022-02-14 06-10-52:00")   -->2022-02-14 

       6.date_format(string s,string format)                //返回指定格式的时间日期

select date_format("2022-02-14 06-10-52:00","yyyy-MM-dd"); ==>2022-02-14

   2.3  获取年、季、月、日、时、分、秒

        7. year(string date)

        8.month(string date)

        9.day(string date)

        10.hour(string date)

        11.minute(string date)

        12.second(string date)

        13.weekday(string date)           //星期几(中国时间方式)

        14.dayofweek(string date)        //星期几(美国时间方式)

        15.last_day(string date)            //当月最后一天

        16.trunc(string date,string format)        //返回当月、当年的的都一天

select trunc("2022-02-14 06-10-52:00","YYYY");   ==>2022-01-01
select trunc("2022-02-14 06-10-52:00","MM");     ==>2022-02-01

  2.4 时间运算函数

        17.add_months(strirng date ,int n)        //增加月份 ,n为负数的时候为较少月份

        18.date_add(string date,int n)               //增加日期,n为负数的时候为减少天数

        19.date_sub(string date,int n)                //减少日期

        20.datediff(string date1,string date2)     //两个日期相差的天数

select datediff("2022-02-10","2022-01-11")    ==>30
select datediff("2022-01-11","2022-02-10")    ==>-30

        22.months_between(string date1,string date2)   // 两个日期相差的月份   

        23.next_day(string start_date,string day_of_week)        //下一个星期几的日期

                                                day_of_week为“Mon,Tue,Wed,Thu,Fri,Sat,Sun”

     三、字符串函数     

       3.1 字符串处理

          1.lower(string str)   || case(string str)                        //将大写字母转化为小写字母

          2.upper(string str)   || rcase(string str)                        //将小写字母转化为大写字母

          3.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/734277.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号