前兩篇《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