0

For instance, all my users have a coins field. I want to be able to collaborate all the coins gained between all the users but unsure of how to query it.

this is my current query, i have tried using this query.

 $query = mysql_query("SELECT `coins` FROM `users` WHERE `coins` > 0");
        echo mysql_result($query, 0);
1
  • 2
    SELECT SUM(coins) as sum FROM users where coins > 0.. Commented Apr 26, 2013 at 9:21

3 Answers 3

1

SELECT SUM(coins) FROM users should work.

ref: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

Sign up to request clarification or add additional context in comments.

Comments

1
select SUM(coins) as Total_Coins from users

Comments

1

You need to use the SUM() function:

SELECT SUM(`coins`) AS `total` FROM `users` WHERE `coins` > 0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.