非常密切相关SQL - 从数据库中选择最“活跃”的时间跨度 https://stackoverflow.com/questions/12938302/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)