SQL/Impala : return 具有最新时间戳的非重复对象的记录
SQL/Impala : return records for non-duplicated object with the latest timestamp
在 Impala/SQL 中,是否可以查询查找具有相应最新时间戳的非重复对象的记录?
例如,如果我有 table_1
:
id | timestamp
-----------------------
1 | 2016-01-02
2 | 2016-02-01
1 | 2016-02-04
1 | 2016-03-05
3 | 2016-05-12
3 | 2016-05-15
4 | 2016-07-07
5 | 2016-08-01
我想查询 return 如下数据
id | timestamp
-----------------------
2 | 2016-02-01
1 | 2016-03-05
3 | 2016-05-15
4 | 2016-07-07
5 | 2016-08-01
您可以使用 GROUP BY
查询,如
select id, max(timestamp) as maxStamp
from table_1
group by id;
在 Impala/SQL 中,是否可以查询查找具有相应最新时间戳的非重复对象的记录?
例如,如果我有 table_1
:
id | timestamp
-----------------------
1 | 2016-01-02
2 | 2016-02-01
1 | 2016-02-04
1 | 2016-03-05
3 | 2016-05-12
3 | 2016-05-15
4 | 2016-07-07
5 | 2016-08-01
我想查询 return 如下数据
id | timestamp
-----------------------
2 | 2016-02-01
1 | 2016-03-05
3 | 2016-05-15
4 | 2016-07-07
5 | 2016-08-01
您可以使用 GROUP BY
查询,如
select id, max(timestamp) as maxStamp
from table_1
group by id;