【问题标题】:how to get to_epoch(sysdate-90) in Hive如何在 Hive 中获取 to_epoch(sysdate-90)
【发布时间】:2019-12-06 01:02:53
【问题描述】:

我有一个在 Oracle 中运行良好的查询,但我想在 Hive 中使用相同的查询。

查询:

select count(mem_id)  
from mem 
where cobrand_id = '10001372' 
and user_type_id =1  
and status_ind <>3 
and LAST_ACCESSED >= to_epoch(sysdate-90);

另外,我在 double 中有 LAST_ACCESSED 库。LAST_ACCEESSED 的示例值为:1.554386487E9,不确定这是什么值,我猜这可能是几秒钟。

试过了:

UNIX_TIMESTAMP( string date, string pattern )
FROM_UNIXTIME( bigint number_of_seconds  [, string format] )

运气不好。有人能帮我吗。提前致谢。

【问题讨论】:

    标签: hive hiveql unix-timestamp sysdate


    【解决方案1】:

    看来 1.554386487E9 是同一个unix epoch time 存储在double 中,以工程记数法显示,可以转换为BIGINT。

    检查您的示例:

    select from_unixtime(cast(1.554386487E9 as bigint));
    OK
    2019-04-04 07:01:27
    

    这个时间戳好看吗?

    如果是,则使用unix_timestamp(concat(date_sub(current_date,90),' 00:00:00')) 获取当前日期的纪元时间 - 90 天。

    您的查询已修复:

    select count(mem_id)  
    from mem 
    where cobrand_id = '10001372' 
    and user_type_id =1  
    and status_ind <>3 
    and cast(LAST_ACCESSED as BIGINT) >=  unix_timestamp(concat(date_sub(current_date,90),' 00:00:00'))
    

    【讨论】:

    • 感谢@leftjoin 的回答。我已经尝试了以下。 from_unixtime(unix_timestamp()-90*60*60*24, 'yyyyMMdd');但我在 90 天和 180 天甚至没有任何天都得到了相同的结果。我已经用您的回答替换了我的查询,再次感谢。
    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    相关资源
    最近更新 更多