数据库记录 数据库有张表,n行,20列,我写了一个存储过程,希望求出每一行的平均值,但是每次求的都是最后一行的平均值,前面的每行平均值怎么求啊?这是我的存储过程的部分
as
select
@al= (SELECT
AVG(col)
FROM(
SELECT col = f1 UNION ALL
SELECT col = f2 UNION ALL
SELECT col = f3 UNION ALL
SELECT col = f4 UNION ALL
SELECT col = f5 UNION ALL
SELECT col = f6 UNION ALL
SELECT col = f7 UNION ALL
SELECT col = f8 UNION ALL
SELECT col = f9 UNION ALL
SELECT col = f10 UNION ALL
SELECT col = f11 UNION ALL
SELECT col = f12 UNION ALL
SELECT col = f13 UNION ALL
SELECT col = f14 UNION ALL
SELECT col = f15 UNION ALL
SELECT col = f16 UNION ALL
SELECT col = f17 UNION ALL
SELECT col = f18 UNION ALL
SELECT col = f19 UNION ALL
SELECT col = f20
)A
)
FROM SCMData ------最佳解决方案-------------------- 排序加个编号
select col=f1,no union select col=f2,no....
group by no ------其他解决方案-------------------- select (f1+f2+...+f20)/20.0
from SCMData ------其他解决方案--------------------
select avg(f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14+f15+f16+f17+f18+f19+f20) from SCMData with(nolock)