从今天起减去7天 [英] Subtract 7 days from today

查看:166
本文介绍了从今天起减去7天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有办法在Hive中获得当前日期 - 7,即7天前的日期。而我的表格中的日期格式为 20150910 。 ( yyyyMMdd )。



我试过下面的查询,但它没有返回任何东西。 b

  select * 
from gmr.tedf_cs_mrch_tran
where cpd_dt = FROM_UNIXTIME(
UNIX_TIMESTAMP(
DATE_SUB(
FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'),7),'yyyyMMdd'))
limit 10;

请在此帮助我。



  select * 
from table1


其中dt> = date_sub(from_unixtime(floor(unix_timestamp()/(60 * 24 * 24))* 60 * 24 * 24),7)和
dt < date_sub(from_unixtime(floor(unix_timestamp()/(60 * 24 * 24))* 60 * 24 * 24)),6);


I am new to hive and sql.

Is there any way to get the current date - 7 in Hive, i.e. the date 7 days ago. And date in my table is in the format 20150910. (yyyyMMdd).

I tried below query, but it's not returning anything.

select *
from gmr.tedf_cs_mrch_tran
where cpd_dt = FROM_UNIXTIME(
                 UNIX_TIMESTAMP(
                  DATE_SUB(
                    FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd') , 7 ), 'yyyyMMdd'))
limit 10;

Kindly please help me on this.

解决方案

Have you tried something like this?

select *
from table1
where dt >= date_sub(from_unixtime(floor(unix_timestamp()/(60*24*24))*60*24*24), 7) and
      dt < date_sub(from_unixtime(floor(unix_timestamp()/(60*24*24))*60*24*24)), 6);

这篇关于从今天起减去7天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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