0

如何获得select查询结果的平均值

例子:

select x from dbo.table1 as a
where MONTH(a.mymonth) = 1 AND YEAR(a.myyear) = 2013

可以使用AVG()功能吗?

4

3 回答 3

3

这就是你要找的全部吗?

select AVG(x)
from dbo.table1
where MONTH(mymonth) = 1 AND YEAR(myyear) = 2013

小提琴演示示例

根据您的 x 数据类型,您可能希望将其转换为小数:

SELECT AVG(CAST(x as decimal))
于 2013-02-24T14:22:43.830 回答
0

是否可以使用 AVG() 函数?

是的,将它包裹在 x 周围,所以:

    select AVG(x) from dbo.table1 as a
    where MONTH(a.mymonth) = 1 AND YEAR(a.myyear) = 2013

在这里了解更多信息。

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg

于 2013-02-24T14:25:28.600 回答
0

如果你想平均x你的select查询应该是这样的:

Select AVG(x)
from dbo.table1 as a
where MONTH(a.mymonth) = 1 AND YEAR(a.myyear) = 2013
于 2013-02-24T14:25:35.067 回答