oliverbj
oliverbj

Reputation: 6052

Get sum from multiply rows

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

Answers (2)

John Woo
John Woo

Reputation: 263693

SELECT (SUM(alertpay_cashout) + SUM(paypal_cashout) + SUM(okpay_cashout))  `SUM` 
FROM users

Upvotes: 0

juergen d
juergen d

Reputation: 204746

Add them with +

SELECT SUM(alertpay_cashout + paypal_cashout + okpay_cashout) AS value_sum 
FROM users

Upvotes: 1

Related Questions