0

我有如下形式的数据:

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 选择查询来解决这个问题?

4

1 回答 1

2

我们可以使用 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
于 2014-06-09T11:20:27.667 回答