gpt4 book ai didi

SQL - 从数据库中选择最多 'active' 时间

转载 作者:行者123 更新时间:2023-12-04 15:50:00 32 4
gpt4 key购买 nike

SQL - Select most 'active' timespan fromdb密切相关但不同的问题。

“我有一张交易表。在这张表中,我以 UTC 格式存储交易日期时间。我有几个月的数据,每天大约有 20,000 笔交易。”

会怎样变化

  select datepart(hour, the_column) as [hour], count(*) as total 
from t
group by datepart(hour, the_column)
order by total desc

这样我就可以选择最“活跃”的特定年、月、日、小时、分钟和秒。

澄清一下,我不是在寻找一天中哪个小时或哪个分钟最活跃。相反,哪个时刻最活跃。

最佳答案

Select 
DATEPART(year, the_column) as year
,DATEPART(dayofyear,the_column) as day
,DATEPART(hh, the_column) as hour
,DATEPART(mi,the_column) as minute
,DATEPART(ss, the_column) as second
,count(*) as count from t
Group By
DATEPART(year, the_column)
, DATEPART(dayofyear,the_column)
, DATEPART(hh, the_column)
, DATEPART(mi,the_column)
, DATEPART(ss, the_column)
order by count desc

关于SQL - 从数据库中选择最多 'active' 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12938880/

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