Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hive 将时间戳转换为配置单元中的日期,并获取该日期的数据_Hive - Fatal编程技术网

Hive 将时间戳转换为配置单元中的日期,并获取该日期的数据

Hive 将时间戳转换为配置单元中的日期,并获取该日期的数据,hive,Hive,我有一个这样的问题 select distinct emp,phno,addrs,email from cdv.emp; 现在我只想获取在最新生成日期创建的数据,而不是旧数据。 我在上创建了一个审计列——这是唯一的键和时间戳 从cdv.emp中选择不同的emp、phno、addrs、email 我希望最新的数据基于24小时内生成的列(timestamp)或最大日期使用rank分析函数。它的工作速度比子查询快得多: select distinct emp,phno,addrs,email fro

我有一个这样的问题

select distinct emp,phno,addrs,email from cdv.emp;
现在我只想获取在最新生成日期创建的数据,而不是旧数据。 我在上创建了一个审计列——这是唯一的键和时间戳

从cdv.emp中选择不同的emp、phno、addrs、email


我希望最新的数据基于24小时内生成的
列(timestamp)
或最大日期使用
rank
分析函数。它的工作速度比子查询快得多:

select distinct emp,phno,addrs,email
from
(
select emp,phno,addrs,email,
       rank() over(order by to_date(c.created_on) desc) rn 
  from cdv.emp c
)s
where rn=1;
如果您希望根据
emp、phno、addrs、email获得最新记录,那么您可以使用row_number()而不使用distinct。如果该方法适用,则速度会更快:

select emp,phno,addrs,email
from
(
select emp,phno,addrs,email,
       row_number() over(partition by emp,phno,addrs,email order by to_date(c.created_on) desc) rn 
  from cdv.emp c
)s
where rn=1;

使用
rank
分析函数。它的工作速度比子查询快得多:

select distinct emp,phno,addrs,email
from
(
select emp,phno,addrs,email,
       rank() over(order by to_date(c.created_on) desc) rn 
  from cdv.emp c
)s
where rn=1;
如果您希望根据
emp、phno、addrs、email获得最新记录,那么您可以使用row_number()而不使用distinct。如果该方法适用,则速度会更快:

select emp,phno,addrs,email
from
(
select emp,phno,addrs,email,
       row_number() over(partition by emp,phno,addrs,email order by to_date(c.created_on) desc) rn 
  from cdv.emp c
)s
where rn=1;