前两篇《Max方法:Max API-Medoo使用指南》和《Min方法:Min API-Medoo使用指南》中介绍了如何使用Medoo的Max方法来获取列的最大值,使用Min方法来获取最小值,今天来介绍使用Avg方法取得平均值。php
平均值方法:Avg API,获取列的平均值。html
avg($table, $column, $where) //table [string]: 表名 //column [string]: 将要被计算的目标列 //where (可选)[array]:WHERE子句筛选记录
返回值: [number]:列的平均值。post
提示:返回值的数据类型是数字。spa
$database = new medoo("my_database"); $average = $database->avg("account", "age", [ "gender" => "male" ]); echo "The average age of male user is " . $average;
从以上不难看出,Avg方法和Max/Min方法的使用方式很是相似。这也有利于咱们记忆和使用。.net
Medoo版本: 0.9.1.1 code
原文标题: 平均值方法:Avg API-Medoo使用指南
htm
原文连接: http://loiy.net/post/616.html
get