答案 0 :(得分:2)
这通常使用AVG
的分析版本来完成:
select accelx - avg(accelx) over ()
from mytable;
答案 1 :(得分:0)
只需在子查询中计算AVG
:
SELECT AccelX - (SELECT AVG(AccelX) FROM T)
FROM T
答案 2 :(得分:0)
试试这个:
select t1.accelx - t2.avgx as Z
from TableName as t1
inner join (
select avg(accelx) as avgx
from TableName
) as t2
on 1 = 1
答案 3 :(得分:0)
SELECT t1.accelx - t2.avgx as Z, userName
FROM TableName as t1
JOIN (SELECT userName, avg(accelx) as avgx
FROM TableName
GROUP BY userName) as t2
ON t1.userName = t2.userName
答案 4 :(得分:0)
MSSQL Server上的TSQL具有Windowed功能。 OVER Clause
SELECT
[AccelX]
,[AccelX] - AVG([AccelX]) OVER ()
FROM T