Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

計算查詢中指定欄位中所包含一組值的算術平均值。

語法

Avg ( expr )

expr 佔位元代表 字串運算式 識別包含要平均值之數值數據的欄位,或使用該欄位中的數據執行計算的運算式。 expr 中的操作數可以包含數據表字段的名稱、常數或函數 (可以是固有的或使用者定義的,但不能包含其中一個其他 SQL 匯總函數) 。

註解

Avg 計算的平均值是算術平均值, (除數值數目) 數的總和。 例如,您可以使用 Avg 來計算平均運費。

Avg 函數不會在計算中包含任何 Null 欄位。

您可以在查詢表達式和 QueryDef 物件的 SQL 屬性中使用 Avg ,或是根據 SQL 查詢建立 Recordset 物件。

範例

Expression

結果​​

SELECT Avg ([UnitPrice]) AS Expr1 FROM ProductSales;

傳回數據表 「ProductSales」 中 「UnitPrice」 欄位中所有值的平均值,並顯示在 [表達式1] 欄中。

SELECT Avg ([SalePrice]) AS AvgSalePrice, Avg ([Discount]) AS AvgDiscount FROM ProductSales;

傳回 ProductSales 數據表中的平均 「SalePrice」 和 「Discount」 字段。 結果會分別顯示在 「AvgSalePrice」 和 「AvgDiscount」 欄中,傳回 「Quantity」 售出超過 10 之所有 “SalePrice” 的平均值。 結果會顯示在 「AvgSalePrice」 欄中。

SELECT Abs (Avg ([Discount]) ) AS AbsAverageDiscount FROM ProductSales;

傳回 [折扣] 欄位平均值的絕對值,並顯示在 “AbsAverageDiscount” 欄中。

計算 SQL 函數中的欄位

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×