计算配置单元数据中的大多数条目(模式)

Counting most of entries (mode) in hive data

我无法编写查询来查找用户在 2010 年 3 月 6 日生成的推文数量最多的那一天。

我已经为我的 Twitter 数据创建了 table。

create table twitter.full_text_ts as
select id, cast(concat(substr(ts,1,10), ' ', substr(ts,12,8)) as timestamp) as        ts, lat, lon, tweet
from full_text;

现在我需要查询它以查找特定日期一天中哪个小时的推文最多。

我可以通过输入

查看任何特定日期推文的所有时间戳 (ts)
select ts 
from twitter.full_text_ts
where to_date(ts) = '2010-03-06'
order by ts desc;

这个输出:

2010-03-06  02:10:01 
2010-03-06  02:11:15 and so on.

我想做的是按小时对它们进行分组,这样我就可以看到哪个小时的条目最多。

谢谢,

规模

尝试以下操作:

select DATEPART(HH, ts) [Hour], COUNT(*) [Count]
from twitter.full_text_ts 
where to_date(ts) = '2010-03-06' 
GROUP BY DATEPART(HH, ts) [Hour] 
order by 1 desc;

您可以使用hour()函数:

select hour(ts), count(*) as cnt 
from twitter.full_text_ts
where to_date(ts) = '2010-03-06'
group by hour(ts)
order by cnt desc;