Percentile_disc获取中位数 - 我不想使用AVG,MIN,SUM,MAX

时间:2014-10-30 15:33:37

标签: sql-server reporting-services reporting median

这是我计算中位数的代码:

select distinct srt.Name,

    cast(sum(sr.price) as int) as AvgCost,cast(sum(sr.cost) as int) as 

    AvgTransCost,cast(avg(sr.TotalTimeSpent) as int) as TotalTimeSpent,

    percentile_disc(.5) WITHIN GROUP(ORDER BY avg(sr.price)) OVER(PARTITION BY srt.Name)    AS MedianSpend

在这一行:

percentile_disc(.5) WITHIN GROUP(ORDER BY avg(sr.price)) OVER(PARTITION BY srt.Name)    AS MedianSpend

我无法将其更改为:

(ORDER BY (sr.price))

如果我尝试在没有AVG infront(sr.price)的情况下运行代码,我会收到此错误:

http://i.stack.imgur.com/2jfS0.jpg

如何在不添加AVG,SUM,MIN,MAX之前运行它(sr.price)??

0 个答案:

没有答案