如何在Hive中获取前一天的日期 [英] How to get previous day date in Hive

查看:1103
本文介绍了如何在Hive中获取前一天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Hive的新手.尝试使用以下查询获取前一天的日期:

I am novice to Hive. Trying to get the previous day date using the below query:

SELECT MAX(id) FROM store_rcd_table
WHERE recon_dt = unix_timestamp(date_sub(from_unixtime(unix_timestamp(),
'yyyy-MM-dd'),1),'yyyy-MM-dd')

,但将NULL作为输出.输出应为date(2017-09-23)和MAX(id).

but getting the NULL as output. The output should have been date(2017-09-23) and MAX(id).

也尝试过

Select MAX(id) FROM store_rcd_table
WHERE recon_dt ='2017-09-24';

此查询也没有输出,只是输出OK.

No output for this query also, just OK is coming as an output.

没有得到什么问题?任何建议/帮助表示赞赏.

Not getting what the issue is? Any suggestion/ help is appreciated.

表的结构为:

id              string                                      
locationid      string                                      
mngrid          string                                      
empid           string                                                                          
deleted         boolean                                     
recon_dt        string                                      

推荐答案

尝试select date_sub(current_date, 1);

0: jdbc:hive2://hiveserver2:1> select date_sub(current_date, 1);
+-------------+--+
|     _c0     |
+-------------+--+
| 2017-09-24  |
+-------------+--+
1 row selected (0.182 seconds)

原始尝试是date_sub(CAST(unix_timestamp()*1000 AS TIMESTAMP), 1),但显然这是错误的.查看评论

Original attempt was date_sub(CAST(unix_timestamp()*1000 AS TIMESTAMP), 1) but apparently that's wrong. See comments

随时阅读配置单元日期函数 >

如果没有结果,则应检查源数据以查看recon_dt的实际含义. (还值得指出的是,您在问题中使用了两个不同的表)

If you get no results, you should check the source data to see what recon_dt actually is. (Also worth pointing out that you used two different tables in the question)

这篇关于如何在Hive中获取前一天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆