@malloc

导航

HIVE函数

1、日期函数

select from_unixtime(unix_timestamp(),'YYYYMMdd HHmmss');//以format格式获取当前时间字符串
select pmod(datediff(from_unixtime(unix_timestamp(),'YYYY-MM-dd'),'2019-01-06'),7);//取得当前周别
select weekofyear(from_unixtime(unix_timestamp(),'YYYY-MM-dd HH:mm:ss'));//只有这种'YYYY-MM-dd HH:mm:ss'格式识别为日期字符串,获取一年第几周
select trunc(from_unixtime(unix_timestamp(),'YYYY-MM-dd HH:mm:ss'),'YY';//当前时间这一年的第一天 'MM'当月第一天
select date_add(from_unixtime(unix_timestamp()),1) from dual; //当前时间加一天返回STRING,-1减一天 date_add(STRING start_date,INT days) 返回2019-01-24
select date_sub(from_unixtime(unix_timestamp()),1) from dual; //当前时间减一天 unix时间戳是指从1970年1月1日所经过的秒数
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('2019-01-01 06:00:00')+3600) FROM DUAL; //指定时间增加3600秒

2、表生成函数

//Array()输入多列,返回多列数据组成的数组
select ARRAY(pnl_id,factory) as array from mdw.test;
//explode()输入数组,遍历数组每个对象返回一行
select explode(ARRAY(pnl_id,factory)) as explode from mdw.test;

二、窗口函数(https://blog.csdn.net/yangshaojun1992/article/details/84074863)

sum(id) over (partition by name order by id RANGE/ROWS  between 1 preceding AND 2 following)
order by 不加 between 默认为 range between unbounded preceding AND CURRENT ROW

 

posted on 2019-06-18 16:26  malloc+  阅读(247)  评论(0编辑  收藏  举报