查询以查找特定时间间隔内的元素

Query to find elements in particular time interval

我需要找到一个 Hive 查询,returns 自 00:00:00、

以来每 6 分钟间隔的 2 个顶级名称

数据看起来像-

Name    Time
A   00:00:00
B   00:03:53
C   00:01:16
A   00:04:34
A   00:07:32
A   00:18:36
C   00:16:12
C   00:05:04
B   00:01:50
B   00:12:05
A   00:11:20
B   00:04:27
B   00:02:47
A   00:00:23
A   00:00:23
B   00:36:21
B   00:02:46

我想在 Hive 中编写查询,这对我来说很新,但即使使用 mysql 查询,我也可以在 Hive 中得出结果。

select 
* 
from
(
select NAME
, time_interval_6
, rank() over (partition by NAME, time_interval_6 order by ct desc) as ranking
from
  (select count(1) as ct
  ,  NAME
  ,  floor((floor(cast(substring(time,1,2) as int)*60 + cast(substring(time,4,2) as int)))/6) as time_interval_6
FROM MY_TABLE
  group by NAME,  floor((floor(cast(substring(time,1,2) as int)*60 + cast(substring(time,4,2) as int)))/6)
   ) a
)b
where ranking <= 2
;