前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Hive常用函数

Hive常用函数

原创
作者头像
硅谷子
发布2022-03-25 19:06:32
1.3K0
发布2022-03-25 19:06:32
举报
文章被收录于专栏:Bigdata

常用日期函数

unix_timestamp:返回当前或指定时间的时间戳

select unix_timestamp(); select unix_timestamp("2020-10-28",'yyyy-MM-dd');

from_unixtime:将时间戳转为日期格式

select from_unixtime(1603843200);

current_date:当前日期

select current_date;

current_timestamp:当前的日期加时间

select current_timestamp;

to_date:抽取日期部分

select to_date('2020-10-28 12:12:12');

year:获取年

select year('2020-10-28 12:12:12');

month:获取月

select month('2020-10-28 12:12:12');

day:获取日

select day('2020-10-28 12:12:12');

hour:获取时

select hour('2020-10-28 12:12:12');

minute:获取分

select minute('2020-10-28 12:12:12');

second:获取秒

select second('2020-10-28 12:12:12');

weekofyear:当前时间是一年中的第几周

select weekofyear('2020-10-28 12:12:12');

dayofmonth:当前时间是一个月中的第几天

select dayofmonth('2020-10-28 12:12:12');

months_between: 两个日期间的月份

select months_between('2020-04-01','2020-10-28');

add_months:日期加减月

select add_months('2020-10-28',-3);

datediff:两个日期相差的天数

select datediff('2020-11-04','2020-10-28');

date_add:日期加天数

select date_add('2020-10-28',4);

date_sub:日期减天数

select date_sub('2020-10-28',-4);

last_day:日期的当月的最后一天

select last_day('2020-02-30');

date_format(): 格式化日期

select date_format('2020-10-28 12:12:12','yyyy/MM/dd HH:mm:ss');

常用取整函数

round: 四舍五入

select round(3.14); select round(3.54);

ceil: 向上取整

select ceil(3.14); select ceil(3.54);

floor: 向下取整

select floor(3.14); select floor(3.54);

常用字符串操作函数

upper: 转大写

select upper('low');

lower: 转小写

select lower('low');

length: 长度

select length("atguigu");

trim: 前后去空格

select trim(" atguigu ");

lpad: 向左补齐,到指定长度

select lpad('atguigu',9,'g');

rpad: 向右补齐,到指定长度

select rpad('atguigu',9,'g');

regexp_replace:使用正则表达式匹配目标字符串,匹配成功后替换!

SELECT regexp_replace('2020/10/25', '/', '-');

集合操作

size: 集合中元素的个数

select size(friends) from test3;

map_keys: 返回map中的key

select map_keys(children) from test3;

map_values: 返回map中的value

select map_values(children) from test3;

array_contains: 判断array中是否包含某个元素

select array_contains(friends,'bingbing') from test3;

sort_array: 将array中的元素排序

select sort_array(friends) from test3;

grouping_set:多维分析

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 常用日期函数
    • unix_timestamp:返回当前或指定时间的时间戳
      • from_unixtime:将时间戳转为日期格式
        • current_date:当前日期
          • current_timestamp:当前的日期加时间
            • to_date:抽取日期部分
              • year:获取年
                • month:获取月
                  • day:获取日
                    • hour:获取时
                      • minute:获取分
                        • second:获取秒
                          • weekofyear:当前时间是一年中的第几周
                            • dayofmonth:当前时间是一个月中的第几天
                              • months_between: 两个日期间的月份
                                • add_months:日期加减月
                                  • datediff:两个日期相差的天数
                                    • date_add:日期加天数
                                      • date_sub:日期减天数
                                        • last_day:日期的当月的最后一天
                                          • date_format(): 格式化日期
                                          • 常用取整函数
                                            • round: 四舍五入
                                              • ceil: 向上取整
                                                • floor: 向下取整
                                                • 常用字符串操作函数
                                                  • upper: 转大写
                                                    • lower: 转小写
                                                      • length: 长度
                                                        • trim: 前后去空格
                                                          • lpad: 向左补齐,到指定长度
                                                            • rpad: 向右补齐,到指定长度
                                                              • regexp_replace:使用正则表达式匹配目标字符串,匹配成功后替换!
                                                              • 集合操作
                                                                • size: 集合中元素的个数
                                                                  • map_keys: 返回map中的key
                                                                    • map_values: 返回map中的value
                                                                      • array_contains: 判断array中是否包含某个元素
                                                                        • sort_array: 将array中的元素排序
                                                                          • grouping_set:多维分析
                                                                          相关产品与服务
                                                                          云数据库 SQL Server
                                                                          腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
                                                                          领券
                                                                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档