zoukankan      html  css  js  c++  java
  • 25.AVG 函数

    定义和用法

    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
  • 相关阅读:
    Codeforce 270A
    Codeforce 513A
    Codeforce 834A
    51Nod 1433 0和5
    51Nod 1005 大数加法
    51Nod 1136 欧拉函数
    51Nod 1449 砝码称重 (二进制思想)
    Codeforce 459A
    Codeforce 515A
    Codeforce 474A
  • 原文地址:https://www.cnblogs.com/yejibigdata/p/6376268.html
Copyright © 2011-2022 走看看