[英]Show date ranges for each unique value of a column (HIVE-QL Query)
I have a HIVE table like this (only showing first 5 lines out of thousands):我有一个这样的 HIVE 表(只显示前 5 行):
date metric timestamp value
2020-06-18 cpu_mem 2020-08-15 00:05:00 10
2020-10-18 cpu_mem 2020-08-15 00:10:00 15
2020-22-18 gpu_mem 2020-08-15 00:15:00 12
2020-26-18 cpu_mem 2020-08-15 00:20:00 10
2020-29-18 threads 2020-08-15 00:25:00 05
I want to show date ranges for each unique metric of a column.我想显示列的每个唯一指标的日期范围。 The result would look like:
结果将如下所示:
unique_metrics date_range(min/max)
cpu_mem 2019-08-10 00:05:00 - 2020-02-15 00:05:00
gpu_mem 2020-08-15 00:05:00 - 2020-09-10 00:15:00
threads 2018-06-09 00:05:00 - 2020-08-15 00:06:00
I am just showing example mins and maxes for the dates.我只是显示日期的示例最小值和最大值。 So the query would return only the unique names of the metrics and the min and max of the dates for those unique metrics.
因此,查询将仅返回指标的唯一名称以及这些唯一指标的日期的最小值和最大值。
Something like:就像是:
SELECT metric, timestamp FROM table WHERE timestamp >= MIN(timestamp) AND timestamp <= MAX(timestamp) GROUP BY metric;
But obviously that's not right, since I don't want to select between a given range I just want to know what the range is for each unique metric.但显然这是不对的,因为我不想在给定范围之间进行选择,我只想知道每个唯一指标的范围是多少。
So the query would return only the unique names of the metrics and the min and max of the dates for those unique metrics.
因此,查询将仅返回指标的唯一名称以及这些唯一指标的日期的最小值和最大值。
Do you just want aggregation?你只是想要聚合吗?
select metric, min(timestamp) min_timestamp, max(timestamp) max_timestamp
from mytable
group by metric
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.