SQL - 从db选择最“活跃”的时间段 [英] SQL - Select most 'active' timespan fromdb

查看:193
本文介绍了SQL - 从db选择最“活跃”的时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张交易表。在这个表中,我将事务日期时间以UTC为单位。我有几个月的数据,每天大约有20,000个交易。



我将如何编写一个存储过程:



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆