use mysql SUM() in a WHERE clause
You can only use aggregates for comparison in the HAVING clause: GROUP BY … HAVING SUM(cash) > 500 The HAVING clause requires you to define a GROUP BY clause. To get the first row where the sum of all the previous cash is greater than a certain value, use: SELECT y.id, y.cash FROM (SELECT t.id, … Read more