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;