Code-Samples/php/Php-sum.php Using SUM Function in Mysqli connect_error) { die("Connection not established: " . $connection->connect_error); } $query = "Use Hospital;"; $connection->query($query); // Using SUM Function $query = "SELECT SUM(patient_age) ". "FROM Patient "; $output = $connection->query($query); if ($output->num_rows > 0) { // output data of each row while($row = $output->fetch_assoc()) { echo "Average of Age " . $row["SUM(patient_age)"]."
"; } } else { echo "0 results"; } $connection->close(); ?>