What are the advantages and disadvantages of using SUM() and GROUP BY in SQL queries for data manipulation in PHP?

When using SUM() and GROUP BY in SQL queries for data manipulation in PHP, the advantage is that you can easily calculate the sum of values in a specific column and group the results based on a certain criteria. This can be useful for generating reports or analyzing data. However, the disadvantage is that it can be resource-intensive for large datasets and may slow down the query execution time.

// Example SQL query using SUM() and GROUP BY
$query = "SELECT category, SUM(price) AS total_price FROM products GROUP BY category";
$result = mysqli_query($conn, $query);

// Loop through the results
while($row = mysqli_fetch_assoc($result)) {
    echo "Category: " . $row['category'] . " Total Price: " . $row['total_price'] . "<br>";
}