“我有一个交易表。在这个表中,我将交易日期时间存储在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