码迷,mamicode.com
首页 > 其他好文 > 详细

25.AVG 函数

时间:2017-02-07 23:40:22      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:实例   name   column   pre   idt   语法   计算   tab   sql   

定义和用法

AVG 函数返回数值列的平均值。NULL 值不包括在计算中。

SQL AVG() 语法

SELECT AVG(column_name) FROM table_name

SQL AVG() 实例

我们拥有下面这个 "Orders" 表:

O_IdOrderDateOrderPriceCustomer
1 2008/12/29 1000 Bush
2 2008/11/23 1600 Carter
3 2008/10/05 700 Bush
4 2008/09/28 300 Bush
5 2008/08/06 2000 Adams
6 2008/07/21 100 Carter

例子 1

现在,我们希望计算 "OrderPrice" 字段的平均值。

我们使用如下 SQL 语句:

SELECT AVG(OrderPrice) AS OrderAverage FROM Orders

结果集类似这样:

OrderAverage
950

例子 2

现在,我们希望找到 OrderPrice 值高于 OrderPrice 平均值的客户。

我们使用如下 SQL 语句:

SELECT Customer FROM Orders
WHERE OrderPrice>(SELECT AVG(OrderPrice) FROM Orders)

结果集类似这样:

Customer
Bush
Carter
Adams

25.AVG 函数

标签:实例   name   column   pre   idt   语法   计算   tab   sql   

原文地址:http://www.cnblogs.com/yejibigdata/p/6376268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!