类型转换函数
cast强制转换
select cast("5" as int)---------将字符串5转换为int类型
字符串转成时间戳
select unix_timestamp("2018/09/20 19:50:29","yyyy/MM/dd HH:mm:ss");
数学运算符
round------正数的四舍五入,负数的五舍六入:select round (5.4)-----5
round(5.1235,3)----保留3位小数的四舍五入5.134
ceil----------天花板(向上取整):select ceil(5.4)-------6
floor----地板(向下取整):select floor(5.6)---------5
abs-----绝对值:select abs(-5.3)---------5.3
greatest----最大值(一行最少需要两个为数字类型的字段):select greatest(3,5,8,2)-----8
least------最小值(一行最少需要两个为数字类型的字段):select least(3,5,8,2)-----2
select max(一组字段可以是任意类型)----------取最大值的聚合函数
select min(一组字段可以是任意类型)----------取最小值的聚合函数
字符串函数
截取字段固定长度:
substr(字段名,0/1(第一个字符),20(截取长度,如果不写直接截取到最后))
拼接字符串函数
concat(string A,string B....)
concat_ws(分隔符,string A,string B....)
length(字符串)------字符串的长度
切割字符串
select split('18:male:beijing',':');返回数组
注意:select split('192.168.2.4','.')是不能分割的,因为.是正则表达式的特殊字符
所以应该为select split('192.168.2.4','\\.')
转大写
upper(string)
时间函数
select current_timestamp---hive时间戳2017-07-30 13:35:46
select unix_timestamp----------自1970年到现在的毫秒时间戳1505618789
转换函数:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss(转换后的格式)')Unix时间戳转换为字符串
select unix_timestamp("2016/09/20 13:40:46","yyyy/MM/dd HH:mm:ss")字符串转换为Unix时间戳
select to_date("2016/09/20 13:40:46")字符串转成日期