zoukankan      html  css  js  c++  java
  • 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做各种聚合。

  • 相关阅读:
    hdu2083
    斐波那数
    hdu2000~hdu2099
    hdu2070
    hdu2071
    hdu2095
    TSINGSEE青犀视频云边端架构视频直播点播平台/人脸识别系统EasyDSS 如何开启debug 日志?
    RTMP协议视频直播点播智能分析平台EasyDSS如何增加Stream模块实现TCP代理?
    RTMP推流平台/视频直播点播分析平台/人脸识别系统EasyDSS如何实现RTMP负载均衡?
    关于视频智能分析平台人脸识别/车牌识别系统EasyDSS登录及直播点播的安全防盗链验证说明
  • 原文地址:https://www.cnblogs.com/ellencc/p/10436822.html
Copyright © 2011-2022 走看看