How can aggregation functions in MySQL be used to calculate the total number of guests across multiple rooms?

To calculate the total number of guests across multiple rooms in MySQL, we can use the SUM() aggregation function to add up the number of guests in each room. We can achieve this by grouping the data by room and then summing up the guest counts for each room.

<?php
// Connect to MySQL database
$conn = new mysqli("localhost", "username", "password", "dbname");

// Query to calculate total number of guests across multiple rooms
$query = "SELECT SUM(guest_count) AS total_guests FROM rooms GROUP BY room_id";

// Execute the query
$result = $conn->query($query);

// Fetch the total number of guests
$totalGuests = $result->fetch_assoc()['total_guests'];

// Display the total number of guests
echo "Total number of guests across multiple rooms: " . $totalGuests;

// Close database connection
$conn->close();
?>