hive不常用函式

2021-08-14 09:12:30 字數 697 閱讀 4592

計算天數差函式

在計算留存時,常會用到天數差函式datediff

select datediff('2017-08-03','2017-08-02') ; # 結果為1

根據日期計算星期幾

有時會遇到根據日期計算星期幾的情況,實現的方法是和某乙個的固定的週日的日期做天數差,再對7取餘

select pmod(datediff(date, '1995-01-01'), 7);

日期格式轉化

常會遇到帶"-"的日期與不帶"-"的日期相互轉化的情況

select from_unixtime(unix_timestamp('20141110','yyyymmdd'),'yyyy-mm-dd');  # 2014-11-10

字串替換

有時要將字串的某些內容替換為別的,或者刪除某些字元,可用到字串替換

select regexp_replace('11-22','-','/');  # 結果為11/22

解json串

可以解單獨的json串或者巢狀的json串

select get_json_object('}', '$.a.c');

MySQL 函式,不常用的

select abs 9 返回絕對值 select ceiling 2.2 向上取整 select floor 2.2 向上取整 select rand 返回0 1隨機數 select sign x 返回乙個數的正負,正返回1,負返回 1 select char length 反恐精英之生死決奪 返...

Hive常用函式

if判斷 select if 1 1,yes no 返回yes 語法 case expression when condition1 then result1 when condition2 then result2 else result end 例子 case a when 1 then one...

hive常用函式

hive常用函式 1 檢視函式用法 desc function 函式名 desc function extended 函式名 2 獲取array陣列長度 size函式 select size collect list field from table select size split hello ...