中位函数如何在Sql Server中工作

时间:2012-02-06 13:10:13

标签: tsql aggregate-functions

在Oracle中它运作良好......

查询oracle是As Follows

Select   COMPONENT_ID, 
         COMPONENT_NAME, 
         POSITION_ID, 
         POSITION_NAME, 
         CHANNEL_ID, 
         CHANNEL_NAME, 
         Max(METRIC) as METRIC, 
         Max(TTD_ATTN) as TTD_ATTN_Max, 
         Min(TTD_ATTN) as TTD_ATTN_Min, 
         Avg(TTD_ATTN) as TTD_ATTN_Avg, 
         Median(TTD_ATTN) as TTD_ATTN_Med, 
         StdDev(TTD_ATTN) as TTD_ATTN_StdDev, 
         Max(COMPONENT_NO) as COMPONENT_NO,
         DATAMONTH, 
         CHANNEL_ID||'_'||POSITION_ID as CHANNEL_POSITION,    
         CHANNEL_NAME||'_'||POSITION_NAME as CHANNEL_POSITION_NAME 
from     SCNCAAF0461A1894981868ABA.PB36E6D13A82C4609B9488950 
Group By COMPONENT_ID,
         COMPONENT_NAME,
         POSITION_ID,
         POSITION_NAME,
         CHANNEL_ID,
         CHANNEL_NAME,
         DATAMONTH

但对于SQL Server,收到错误

Select   COMPONENT_ID,
         COMPONENT_NAME,
         POSITION_ID,
         POSITION_NAME,
         CHANNEL_ID,
         CHANNEL_NAME,
         max(METRIC) AS METRIC,
         max(TTD_ATTN) AS TTD_ATTN_Max,
         min(TTD_ATTN) AS TTD_ATTN_Min,
         avg(TTD_ATTN) AS TTD_ATTN_Avg,
         Median(TTD_ATTN) AS TTD_ATTN_Med,
         stdev(TTD_ATTN) AS TTD_ATTN_StdDev,
         max(COMPONENT_NO) AS COMPONENT_NO,
         DATAMONTH,
         ISNULL(CHANNEL_ID, '') + '_' + ISNULL(POSITION_ID, '') AS CHANNEL_POSITION,
         ISNULL(CHANNEL_NAME, '') + '_' + ISNULL(POSITION_NAME, '') AS CHANNEL_POSITION_NAME 
from     SCNCAAF0461A1894981868ABA.PB36E6D13A82C4609B9488950 
Group By COMPONENT_ID,    
         COMPONENT_NAME,
         POSITION_ID,
         POSITION_NAME,
         CHANNEL_ID,
         CHANNEL_NAME,
         DATAMONTH

错误:无法正确解析Select语句。无法生成表。

我认为他们的中位数功能存在问题。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

在SQL Server中不存在MEDIAN - 即使在SQL Server 2012中也不存在(尚未进行RTM)。

http://msdn.microsoft.com/en-us/library/ms173454(v=sql.110).aspx

如何使用SQL Server计算中位数的问题是asked / answered here