Code-Samples/php/Php-groupby2.php Using GROUP BY with HAVING Clause in Mysqli connect_error) { die("Connection not established: " . $connection->connect_error); } $query = "Use Hospital;"; $connection->query($query); // Using GROUP BY with HAVING Clause $query = "SELECT patient_age, COUNT(patient_fname) as 'tpatients' ". "FROM Patient ". "GROUP BY patient_age ". "HAVING patient_age > 35"; $output = $connection->query($query); if ($output->num_rows > 0) { // output data of each row while($row = $output->fetch_assoc()) { echo "Age " . $row["patient_age"]." Total Patients " . $row["tpatients"]."
"; } } else { echo "0 results"; } $connection->close(); ?>