我编写查询并获取值
我已经在SQL Server 2012上尝试过此操作
;With CTE_ColorIndicator
AS
(
select Name,Value,Report_Date,
Dense_Rank() Over(Order by Report_Date DESC)Dno,
(AVG(value)+(3*STDEV(value))) UpperLimit,
(AVG(value)+(3*STDEV(value)))*0.85 Limit
from #Temp1
group by Name,value,Report_date
)
Select *
from CTE_ColorIndicator
where Dno <=90 and Dno > 7
“我希望聚合值可以代替“上限”和“限制”列” “但是输出在上限和限制列中显示'NULL'值”
答案 0 :(得分:0)
您正在按value
分组。因此,没有定义标准偏差。我认为您打算将子查询设为:
select Name, Report_Date,
Dense_Rank() Over (Order by Report_Date DESC) as Dno,
(AVG(value) + 3 * STDEV(value)) as UpperLimit,
(AVG(value) + 3 * STDEV(value)) * 0.85 as Limit
from #Temp1
group by Name, Report_date