在hive中要实现
-- 留存收益值
select t1.report_date,now_amount,seven_amount,month_amount FROM
(SELECT report_date,sum(total_amount) AS now_amount FROM jt_sk_ods.place_report t1 GROUP BY report_date) t1
LEFT JOIN (SELECT report_date,sum(total_amount) AS seven_amount FROM jt_sk_ods.place_report GROUP BY report_date) t2 ON date_sub(t1.report_date, 7) = t2.report_date
LEFT JOIN (SELECT report_date,sum(total_amount) AS month_amount FROM jt_sk_ods.place_report GROUP BY report_date) t3 ON date_sub(t1.report_date, 28) = t3.report_date
-- where t1.report_date = '2019-02-17'
ORDER BY t1.report_date
to_date:日期时间转日期函数
select to_date(‘2015-04-02 13:34:12’);
输出:2015-04-02
from_unixtime:转化unix时间戳到当前时区的时间格式
select from_unixtime(1323308943,’yyyyMMdd’);
输出:20111208
unix_timestamp:获取当前unix时间戳
select unix_timestamp();
输出:1430816254
select unix_timestamp(‘2015-04-30 13:51:20’);
输出:1430373080
year:返回日期中的年
select year(‘2015-04-02 11:32:12’);
输出:2015
month:返回日期中的月份
select month(‘2015-12-02 11:32:12’);
输出:12
day:返回日期中的天
select day(‘2015-04-13 11:32:12’);
输出:13
hour:返回日期中的小时
select hour(‘2015-04-13 11:32:12’);
输出:11
minute:返回日期中的分钟
select minute(‘2015-04-13 11:32:12’);
输出:32
second:返回日期中的秒
select second(‘2015-04-13 11:32:56’);
输出:56
weekofyear:返回日期在当前周数
select weekofyear(‘2015-05-05 12:11:1’);
输出:19
datediff:返回开始日期减去结束日期的天数
select datediff(‘2015-04-09’,’2015-04-01’);
输出:8
date_sub:返回日期前n天的日期
select date_sub(‘2015-04-09’,4);
输出:2015-04-05
date_add:返回日期后n天的日期
select date_add(‘2015-04-09’,4);
输出:2015-04-13
从1970-01-01 00:00:00 UTC到指定时间的秒数。
总结:时间戳到日期时间,日期时间到时间戳,日期时间到日期。
获取时间戳:select distinct unix_timestamp() from test_date;
时间戳>>>>日期:select distinct from_unixtime(1441565203,'yyyy/MM/dd HH:mm:ss') from test_date;
2015/09/07 02:46:43
日期时间>>>>>>时间戳:默认格式为“yyyy-MM-dd HH:mm:ss“:
select distinct unix_timestamp('2015-09-07 02:46:43') from test_date;
1441565203
指定日期时间>>>>>>时间戳:
select distinct unix_timestamp('20111207 13:01:03','yyyyMMdd HH:mm:ss') from test_date;
1323234063
//要接受的类型
日期时间>>>>>>日期:
select distinct to_date('2011-12-08 10:03:01') from test_date;
结果:2011-12-08
日期时间>>>>>>年/月/日/时/分/秒: year(string date),month(),day(),hour(),minute(),second()。
select distinct year('2011-12-08 10:03:01') from test_date;
2011
select distinct second('2011-12-08 10:03:01') from test_date;