gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 15:12:36 27 4
gpt4 key购买 nike

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

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

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.

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

谢谢,

卡尔

最佳答案

您可以使用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;

关于sql - 计算配置单元数据中的大多数条目(模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33815889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com