Hive常用的内置函数

发布于:2024-07-04 ⋅ 阅读:(155) ⋅ 点赞:(0)

聚合类

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

网站公告

今日签到

点亮在社区的每一天
去签到