SQL - 从db选择最“活跃”的时间段 [英] SQL - Select most 'active' timespan fromdb
本文介绍了SQL - 从db选择最“活跃”的时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何编写一个存储过程:
A:最活跃/最繁忙的小时计数
B:返回哪个小时是最活跃/最忙的
解决方案
select datepart(hour,the_column)as [hour],count(*)as total
from t
group by datepart(hour,the_column)
order by total desc
I have a table of transactions. In this table I store the transaction datetime in UTC. I have a few months of data, about 20,000 transactions a day.
How would I write a stored procedure to:
A: Count of the most active/busiest hour
B: Return which hour was the most active/busiest
解决方案
select datepart(hour, the_column) as [hour], count(*) as total
from t
group by datepart(hour, the_column)
order by total desc
这篇关于SQL - 从db选择最“活跃”的时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文