hive数据库numeric_hive中常用的函数
目錄:
1.date_sub (string statdate, int days)?--返回到statdate之前int days的日期
2.concat(str1,str2,...)--將多個字符串連接成一個字符串
3.contact_ws(eperator,str1,str2...)--這個函數會跳過分隔符參數后的任何null和空字符串,分隔符將被加到被連接的字符串之間
4.sum(if(category=1,1,0))--sum函數返回一個數值,如果,category=1,則返回1,否則,返回0
count(if(category=1,true,null))--count函數返回一個布爾值類型的數據(即當返回值為true時進行計數)
5.variance(col)--求指定列數值的方差
1.date_sub()函數
作用:返回到statdate之前int days的日期
使用:date_sub (string statdate, int days)
eg:date_sub('2019-02-26',10)--------2019-02-16
題外話:
hive的書寫順序:
select … from … where … group by … having … order by …
hive的執行順序:
from … where … select … group by … having … order by …
2.concat()函數
將多個字符串連接成一個字符串
eg:select id,name from B limt 1
id ?name
1 ? ?lon
concat(str1,str2,...)
返回的結果為連接string產生的字符串,如果其中有任何一個參數為null,則返回的值為null
select concat(id,',',name) col from B limit 1
col
1,lon----------相當于用,把1和lon連接起來了
3.contact_ws(eperator,str1,str2...)
這個函數會跳過分隔符參數后的任何null和空字符串,分隔符將被加到被連接的字符串之間
eg:select concat_ws(',','aa','bb')
'aa,bb'
更新于2019-02-26
4.sum(if())和count(if())
sum(if(category=1,1,0)),sum函數返回一個數值,如果,category=1,則返回1,否則,返回0
count(if(category=1,true,null)),count函數返回一個布爾值類型的數據(即當返回值為true時進行計數),如果category=1,返回true,否則,返回null
count(if(category=1,1,0))--返回的全部都是true,即全部都會計數
5.variance(col)--return the wariance of a numeric column in the group.
求指定列數值的方差
6.lateral view explode()函數
explode()可以將數列類型拆分成多行--行轉列
lateral view可以進行相關的聚合
對應拆分
explode將復雜結構一行拆成多行,然后再用lateral view做各種聚合。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的hive数据库numeric_hive中常用的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中怎么写注释_Python中
- 下一篇: 乐观锁的颗粒度_MySql数据库锁机制详