首页 / 更多教程 / Hive sql常用函数
Hive sql常用函数
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Hive sql常用函数,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2632字,纯文字阅读大概需要4分钟。
内容图文
![Hive sql常用函数](/upload/InfoBanner/zyjiaocheng/520/3d4abeb83cfa43c7be13216640962e05.jpg)
2.时间戳转为日期
from_unixtime(时间戳,string format=yyyy-MM-dd HH:mm:ss) //实际写出来不需要带string,只是表明格式 --时间戳为10位,H为24小时计数,h为12小时计数 --string format:默认标准格式为 yyyy-MM-dd HH:mm:ss --其他格式写法多种多样 yyyy-MM-dd HH:mm --yyyy-MM-dd HH --yyyy-MM-dd --yyyyMMdd --yyyy/MM/dd3.日期转为时间戳
unix_timestamp(string date=当前时间) //实际写出来不需要带string,只是表明格式 --默认为获取当前时间戳:unix_timestamp() --date的格式必须是标准格式:"yyyy-MM-dd HH:mm:ss",如不符合返回null4.时间间隔计算 --(理解:date difference日期差异)
datediff(string enddate,string startdate) --计算方式为:enddate-startdate --结果为天数5.保留年月日
to_date("标准时间格式") --结果为如:2020-03-226.单独年,月,日
year(format_date) month(format_date) day(format_date) -- format_date格式至少包含年月日 -- 如year("2020-03-22") -- year("2020-03-22 12:23")7.日期增加函数
date_add(string startdate,intdays) --如:date_add("2020-03-11",10) -->2020-03-218.日期减少函数
date_sub(string startdate,intdays) --如:date_add("2020-03-11",10) -->2020-03-019.截取字符串
substr(str,pos,len) -- 常用于截取字符串时间 -- pos从1开始算,不是010.条件函数:case when
--如:select case when age<20 then "20岁以下" when age>=20 and age<30 then "20~30岁" when age>=30 and age<40 then "30~40岁" else "40岁以上" end as age_type, count (distinct user_id) user_num from user_info group by ...;11.if函数
if(条件表达式,结果1,结果2) :当条件为真-->结果1,否则结果2 --如:select if (level>5,"高","低") [as level_type] from...12.对json字符串和map类型的处理
get_json_object(string json_string,string path) string json_string:列名 string path:用$.key取值 --如:字段: extra1(string): {"systemtype":"ios","education":"master","marriage_status":"1","phone brand":"iphone X"} --字段: extra2(map<string,string>): {"systemtype":"ios","education":"master","marriage_status":"1","phone brand":"iphone X"} 对于json类型: 例如: SELECT get_json_object(extra1, ‘$.phonebrand‘) as phone_brand, count(distinct user_id) user_num FROM user_info GROUP BY get_json_object(extra1, ‘$.phonebrand‘);对于map类型: 例如:select extra2[‘phonebrand‘] as phone_brand, count(distinct user_id) user_num FROM user_info GROUP BY extra2[‘phonebrand‘];
Hive sql常用函数
标签:日期 inf mon extra _id else 保留 key group
本文系统来源:https://www.cnblogs.com/lverkou/p/13099953.html
内容总结
以上是互联网集市为您收集整理的Hive sql常用函数全部内容,希望文章能够帮你解决Hive sql常用函数所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。