MySQLi Avg

MySQLi AVG is used to return the average value of an expression.

Below the syntax of AVG function.

SELECT AVG(aggregate_expression) FROM table_name [conditions];
<?php
  $conn  = mysqli_connect('localhost:3306', 'user_name', 'password', 'db_nexladder');
  if(! $conn) {
     die('Could not connect: ' . mysqli_error());
 }
  $sql = "SELECT AVG(`working_hours`) AS working_hours FROM `tbl_employee`";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_object($result) ;
  echo "Working Hours: " . $row->working_hours;
  mysqli_close($conn);
?>

Consider a another table "tbl_employee":

mysql create table 2

Below the table structure "tbl_employee":

mysql describe table 2

Insert a Record in table "tbl_employee":

mysql insert table 2

Below it'll look like with AVG Aggregate

mysql avg