Hive常用的内置函数

聚合类

1.指定列值的数目

count()

2.指定列值求和

sum()

3.最大值

max()

4.最小值

min()

5.平均值

avg()

6.中位数函数

percentile(bigint col,p)

7.分位数函数

percentile(bigint col,0.5)

数值类

1.取整函数Round(a)
select rount(99.4567)

在这里插入图片描述
四舍五入计算

2.指定精度取整ROUND(double a,int b)

取b位小数四舍五入

3.向上取整FLOOR()
4.向下取整CEIL()
5.随机数 rand()

值从0-1

6.绝对值函数

abs()

日期类

获取当前日期
select CURRENT_DATE 

2024-07-03

获取当前时间戳
select CURRENT_TIMESTAMP  #### 2024-07-03 11:11:04
日期前后
select date_sub(CURRENT_DATE,1)
select date_add(CURRENT_DATE,1)
日期间隔
select datediff(CURRENT_DATE,'1991-10-04')
select datediff('2024-05-01','1991-10-04')
bigint类型的时间戳
select unix_timestamp('2020-10-01 00:00:00')

1601510400(秒): 从 1970-01-01 00:00:00 到 2020-10-01 00:00:00 过了多少秒

select unix_timestamp()                   

将 bigint 类型的时间戳转换成 我们想要的日期格式

    select from_unixtime(1719976610,'yyyy-MM-dd hh:mm:ss')
    select from_unixtime(1719976610,'yyyy-MM')
日期转换函数, 只保留 年月日
select  to_date('2024-04-09 10:09:45')
日期 提取函数
	year | month | day | hour | minute 
获取年份
select   substr('2024-04-09 10:09:45',1,4)
select  year('2024-04-09 10:09:45')
提取月份
select   substr('2024-04-09 10:09:45',6,2)
select  month('2024-04-09 10:09:45')

字符串

计算长度
select length("abcde")
截取
substr()
大写
upper
小写
lower
去除空格

trim

获取url中的域名

parse_url

select parse_url('https://editor.csdn.net/md?not_checkout=1','HOST')

会返回
editor.csdn.net

获取搜索内容

parse_url

select parse_url('https://editor.csdn.net/md?not_checkout=1','QUERY')

会返回
not_checkout=1

字符串分割
select split('abc,xyz,yyy',',')
从map中取值
select  extra2['systemtype'] from user_info
从string类型的k-v中取值
 select  get_json_object(extra1,'$.systemtype') from user_info
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值