Hive 获取蜂巢中过去7天的记录

Hive 获取蜂巢中过去7天的记录,hive,hiveql,Hive,Hiveql,我在hive中有一个表,如下所示。我想从该表中选择insertdate,customer\u id,其中insertdate为当前日期-7天 原始表格 +------------------------+--------------+ | insertdate | customer_id | +------------------------+--------------+ | 2018-04-21 04:00:00.0 | 39550695 | | 2018

我在
hive
中有一个表,如下所示。我想从该表中选择
insertdate
customer\u id
,其中
insertdate
当前日期-7天

原始表格

+------------------------+--------------+
|       insertdate       | customer_id  |
+------------------------+--------------+
| 2018-04-21 04:00:00.0  | 39550695     |
| 2018-04-22 04:00:00.0  | 38841612     |
| 2018-04-23 03:59:00.0  | 23100419     |
| 2018-04-24 03:58:00.0  | 39550688     |
| 2018-04-25 03:58:00.0  | 39550691     |
| 2018-05-12 03:57:00.0  | 39550685     |
| 2018-05-13 03:57:00.0  | 39550687     |
| 2018-05-14 03:57:00.0  | 39550677     |
| 2018-05-14 03:56:00.0  | 30254216     |
| 2018-05-14 03:56:00.0  | 39550668     |
+------------------------+--------------+
预期结果

+------------------------+--------------+
|       insertdate       | customer_id  |
+------------------------+--------------+
| 2018-05-12 03:57:00.0  | 39550685     |
| 2018-05-13 03:57:00.0  | 39550687     |
| 2018-05-14 03:57:00.0  | 39550677     |
| 2018-05-14 03:56:00.0  | 30254216     |
| 2018-05-14 03:56:00.0  | 39550668     |
+------------------------+--------------+
但是当我尝试下面的方法时,得到的结果是空的

select insert_date, customer_id from table where insert_date = date_sub(current_date, 7);

select insert_date, customer_id from table whereinsert_date = date_sub(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'), 7);
对于以上两个查询,我都得到了空结果


我做错了什么?如何得到正确的结果

假设您需要过去7天的数据,请使用

select insert_date, customer_id 
from table 
where to_date(insert_date) >= date_sub(current_date, 7) 
and to_date(insert_date) < current_date
选择插入日期、客户id
从桌子上
where to_date(插入日期)>=日期子项(当前日期,7)
截止日期(插入日期)<当前日期
查询不显示结果的原因是日期时间格式和日期之间的比较。

请参阅