我有一个我需要修改的查询.它目前每个参考都有一行,15分钟的时间段和相关的帐号.我的目标是每15分钟阻止一行,说明在该阻止期间最常出现的帐号.
SELECT
left(cast(Concat([Hour],':',[Minute]) as time),5) as [Time Block]
,[Reference]
,[Account]
from(
SELECT
DATEPART(hh,[Start Time]) as [Hour]
,[Reference]
,case when DATEPART(mi,[Start Time]) between 00 and 15 then '00'
when DATEPART(mi,[Start Time]) between 15 and 30 then '15'
when DATEPART(mi,[Start Time]) between 30 and 45 then '30'
when DATEPART(mi,[Start Time]) between 45 and 100 then '00'
else 'Error' end AS [Minute]
,[Account]
FROM [iPR].[dbo].[InboundCallsView]
where [Start Time] between '2017-03-21' and '2017-03-22')T
order by [Time Block]
Run Code Online (Sandbox Code Playgroud)
这给出了输出
我不需要参考号码,但我想要
00:00 310523
00:15 310523
00:30 310523
依此类推24小时内每15分钟显示最多行的帐户.这可能吗?
该值在统计中称为模式.它很容易计算:
with cte as (<your query here>)
select timeblock, account
from (select timeblock, account, count(*) as cnt,
row_number() over (partition by timeblock order by count(*) desc) as seqnum
from cte
group by timeblock, account
) t
where seqnum = 1;
Run Code Online (Sandbox Code Playgroud)
如果是最常见的联系,则会任意返回一个值.如果你想要所有这些,那么使用rank()或dense_rank().
| 归档时间: |
|
| 查看次数: |
212 次 |
| 最近记录: |