0

我在 sql 中有一个存储过程,它给了我一些列的平均值:

ALTER PROCEDURE [dbo].[Financial] 

AS
BEGIN
    select avg([aa ]) as 'aaa',
    avg([bb]) as 'bbb',
    avg([cc ]) as 'ccc',
    avg([dd]) as 'ddd',
    avg([ee]) as 'eee',
    avg([ ff]) as 'fff'
from [FIN]
END

现在我的问题是如果我想为这个过程的结果给出平均值,我该怎么办?你知道这个过程的结果是一行,现在我想获得这一行的平均值。我应该在我目前的程序中添加什么?

4

1 回答 1

0

您可以使用子查询:

select ([aaa]+[bbb]+[ccc]+[ddd]+[eee]+[fff])/6 as avg from
(select avg([aa ]) as 'aaa',
    avg([bb]) as 'bbb',
    avg([cc ]) as 'ccc',
    avg([dd]) as 'ddd',
    avg([ee]) as 'eee',
    avg([ ff]) as 'fff'
from [FIN]) sub;
于 2012-10-01T16:11:33.547 回答