我们已将SQL Server跟踪加载到包含以下字段的表
StartTime,Duration,Object_name,DatabaseID,HostName,&应用程序名。
如何按小时,Object_name,DatabaseID,HostName和&amp ;;计算平均持续时间分组的第95百分位数。应用名称?
谢谢。
答案 0 :(得分:2)
您似乎知道问题的答案。它是这样的:
select avg(duration) as avg_duration,
percentile_cont(0.95) within group (order by avg(duration)) over () as percentile_95
from t
group by hour, Object_name, DatabaseID, HostName, ApplicationName;
注意:这会将值放在每一行上。我倾向于使用以下单值:
select top (1) percentile_cont(0.95) within group (order by avg_duration) over () as percentile_95
from (select avg(duration) as avg_duration,
percentile_cont(0.95) over (order by avg(duration)) as percentile_95
from t
group by hour, Object_name, DatabaseID, HostName, ApplicationName
) t;