比喻:统计最近一周0点到10点期间每天id的数量
日期:2023-03-23 09:02:22 日期全是这种格式
第一步先把日期转小时:先把小于10小时的查出来
toHour(card_time)<10
select toDate(t.dates) as dates,sum(t.count) as count from (
select toStartOfHour(card_time) as dates,count(query) as count from 表
where toDate(card_time) between '' and ''
and toHour(card_time)<10
group by dates order by count) t
group by dates order by dates,count desc
主要思路是:先把日期转换为:2023-02-01 08:00:00 通过toStartOfHour(card_time)转换,然后统计每个时间,比喻8点访问的id数量,然后把从0点到10点每个时间段访问id的数据进行统计。
这是第一层的思路
第二层的思路:
把第一层里面的toStartOfHour(card_time)转换成toDate格式,然后group by toDate(dates), sum(count)把每天的每个时间段的count(query)进行累加。
该文描述了一种方法来统计最近一周内每天0点到10点各小时的ID数量。首先,通过toStartOfHour函数将时间转换至每天的小时开始时刻,然后对0到10点的数据进行计数并按日期分组。在第二步中,进一步将小时数据转换为日期,并累加每个日期内的小时计数。
1411

被折叠的 条评论
为什么被折叠?



