DECLARE @Sample TABLE(@x float, @y float)
SET @x = SELECT [Return] x
FROM [return]
WHERE YM BETWEEN 8801 AND 8901
AND Radif = 2
SET @y = SELECT [Return] y
FROM [return]
WHERE YM BETWEEN 8801 AND 8901
AND Radif = 2
;WITH cteSource(x, xAvg, y, yAvg, n) AS
(
SELECT
1E * x,
AVG(1E * x) OVER (PARTITION BY (SELECT NULL)),
1E * y,
AVG(1E * y) OVER (PARTITION BY (SELECT NULL)),
COUNT(*) OVER (PARTITION BY (SELECT NULL))
FROM
@Sample
)
SELECT
SUM((x - xAvg) *(y - yAvg)) / MAX(n) AS [COVAR(x,y)]
FROM
cteSource
答案 0 :(得分:2)
它可能有多个错误。但从前三行开始没有任何意义:
DECLARE @Sample table( @x float , @y float)
set @x = SELECT [Return]x FROM [return] where YM between 8801 and 8901 and Radif=2
set @y = SELECT [Return]y FROM [return] where YM between 8801 and 8901 and Radif=2;
我最近能猜到,你想要这样的东西:
DECLARE @Sample table(x float, y float);
INSERT INTO @Sample(x, y )
SELECT x, y
FROM [return]
WHERE YM between 8801 and 8901 and Radif = 2;
(这可能不是你想要的。这只是猜测。)
前三行有很多错误,我最好的建议就是了解T-SQL编码和SQL语法。