我正在写Percentile_CONT函数,结果返回多行。我假设PERCENTILE_CONT函数应该只返回一个值。这是我的SQL
select PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY RegoToSrvc DESC)
OVER (PARTITION BY Hospid) as MedianSeconds,
'MedianWaitTime' as Flag
from A
where A.RegistrationDate between '20140701' and '20140731' and
Hospid = 21
答案 0 :(得分:2)
您正在使用窗口函数,因此集合中的行数没有减少。如果你想要中位数,只需要一行:
select TOP 1 PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY RegoToSrvc DESC)
OVER (PARTITION BY Hospid) as MedianSeconds,
'MedianWaitTime' as Flag
from A
where A.RegistrationDate between '20140701' and '20140731' and
Hospid = 21;