Hive:select 集合中的最新项
Hive: select the most recent item from the set
我正在寻找一种从 Hive 中的集合中选择最新项(日期)的方法。例如有以下 table t1
:
item date
a 2016-01-01
a 2016-02-04
b 2016-01-10
之后
hive> select item, collect_set(date) as dates from t1 group by item;
我有
item dates
a [2016-01-01, 2016-02-04]
b [2016-01-10]
所以现在我需要摆脱过时的日期,即创建 table like
item date
a 2016-02-04
b 2016-01-10
有人能帮忙吗?
只需使用max()
:
select item, max(date) as date
from t1
group by item;
如果你真的想要一个新的table,你可以使用create table as
。
我正在寻找一种从 Hive 中的集合中选择最新项(日期)的方法。例如有以下 table t1
:
item date
a 2016-01-01
a 2016-02-04
b 2016-01-10
之后
hive> select item, collect_set(date) as dates from t1 group by item;
我有
item dates
a [2016-01-01, 2016-02-04]
b [2016-01-10]
所以现在我需要摆脱过时的日期,即创建 table like
item date
a 2016-02-04
b 2016-01-10
有人能帮忙吗?
只需使用max()
:
select item, max(date) as date
from t1
group by item;
如果你真的想要一个新的table,你可以使用create table as
。