How can the SQL query be modified to calculate the sum of each row instead of the total sum?

To calculate the sum of each row instead of the total sum in SQL, we can modify the query to include a SUM() function along with a GROUP BY clause. By grouping the rows based on a specific column, we can calculate the sum for each group of rows separately. This allows us to get the sum of each row individually rather than the total sum across all rows.

$query = "SELECT column1, column2, SUM(column3) AS row_sum 
          FROM table_name 
          GROUP BY column1, column2";
$result = mysqli_query($connection, $query);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "Sum of row with " . $row['column1'] . " and " . $row['column2'] . " is: " . $row['row_sum'] . "<br>";
    }
} else {
    echo "No rows found.";
}