简体   繁体   English

Hive查询不返回输出

[英]Hive query is not returning output

Hive query is not returning the data (0 number of rows). Hive查询不返回数据(0行数)。

need to retrieve 1 month back records from till/current date from the table. 需要从表中检索从当前日期开始的1个月后退记录。

select * from table1 
where date_format(order_date,'yyyy-MM-dd') >= date_format(add_months(current_date,-1),'yyyy-MM-01')
and date_format(order_date,'yyyy-MM-dd') <= date_format(current_date,'yyyy-MM-dd');

need to retrieve past 1 month data to till date. 需要检索过去1个月的数据到目前为止。

I think, you can use "BETWEEN". 我想,你可以使用“BETWEEN”。 Because you work between two dates and maybe more than performances 因为你在两个日期之间工作,也许比表演更多

SELECT *
  FROM your_table
  WHERE your_date_column BETWEEN '2018-09-01' AND '2019-06-01';

Adding to the previous answer, the following is the code which you should definitely be trying out 添加到上一个答案,以下是您应该尝试的代码

The DATE_SUB function in hive allows you to subtract dates by integers, thus 30 in our case denotes a month** 配置单元中的DATE_SUB函数允许您按整数减去日期,因此在我们的情况下30表示一个月**

To cast your strings to dates, you may use TO_DATE() or DATE() functions. 要将字符串转换为日期,可以使用TO_DATE()DATE()函数。

** definition of a month varies with your use case. **一个月的定义因您的使用情况而异。 In this case, we are considering a 30 days gap as a month. 在这种情况下,我们考虑将30天的差距作为一个月。 If your use case requires calendar months to be considered as a month, use add_months function instead 如果您的用例要求将日历月视为一个月,请改用add_months函数

         SELECT columns 
            from TABLE_NAME 
            WHERE YOUR_DATE_COLUMN_NAME 
                  BETWEEN DATE(CURRENT_DATE) AND DATE_SUB(CURRENT_DATE, 30)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM