【问题标题】:Hive select query with Group by minute按分钟分组的 Hive 选择查询
【发布时间】:2014-07-23 17:15:52
【问题描述】:

我有如下形式的数据:

hive> desc test;
no string
txdate string
hive>

hive> select * from test;

1  2014-06-01 10:12:12.100

1  2014-06-01 10:12:14.100

1  2014-06-01 10:12:16.100

1  2014-06-01 10:13:12.100

1  2014-06-01 10:14:12.100

我需要使用 txdate 列对数据进行分组并截断到最后一分钟。输出应如下所示

3  2014-06-01 10:12:00

1  2014-06-01 10:13:00

1  2014-06-01 10:14:00

谁能帮我用 Hive 选择查询来解决这个问题?

【问题讨论】:

  • 您想告诉我们您的尝试吗?您可以在HIVE 中使用GROUP BY
  • 看看from_unixtime()和unix_timestamp()

标签: date select group-by hive minute


【解决方案1】:

我们可以使用 substr() 函数来实现这一点。

查询是:

select substr(txdate,1,16), sum(no) from test group by substr(txdate,1,16);

这个查询的结果将是

2014-06-01 10:12 3
2014-06-01 10:13 1
2014-06-01 10:14 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    相关资源
    最近更新 更多