Reputation: 6052
How can I take the sum of more than one row in my database?
Currently I have this:
$result = mysql_query('SELECT SUM(alertpay_cashout,paypal_cashout,okpay_cashout) AS value_sum FROM users');
$row = mysql_fetch_assoc($result); $sum = $row['value_sum'];
As you can see, I wish to get the sum from alertpay_cashout, paypal_cashout and okpay_cashout from all my users.
The above code does not work.
Upvotes: 0
Views: 118
Reputation: 263693
SELECT (SUM(alertpay_cashout) + SUM(paypal_cashout) + SUM(okpay_cashout)) `SUM`
FROM users
Upvotes: 0
Reputation: 204746
Add them with +
SELECT SUM(alertpay_cashout + paypal_cashout + okpay_cashout) AS value_sum
FROM users
Upvotes: 1