Reputation: 2349
This is My Query :
SELECT user,name,SUM(price) FROM $tableName WHERE faktor='1' GROUP BY user ORDER BY SUM(price) ASC
This Query Work , but i want to Show Who Have Sum(price) Bigger Than 100 $ .
i test it with WHERE SUM(Price) < '100'
but not work , and Result is wrong.
Thanks ;)
Upvotes: 1
Views: 5996
Reputation: 22646
Try using HAVING
SELECT user,name,SUM(price) FROM $tableName WHERE faktor='1'
GROUP BY user
HAVING SUM(Price) < 100
ORDER BY SUM(price) ASC
Upvotes: 1
Reputation: 5666
To evaluate values from accumulative functions in a query you need to use the HAVING clause of the query.
Upvotes: 2
Reputation: 45721
Lookup the HAVING
-sql clause. It acts as a WHERE
but is applied to a GROUP
:
SELECT user,name,SUM(price)
FROM $tableName
WHERE faktor='1'
GROUP BY user
HAVING SUM(price) > 100
ORDER BY SUM(price) ASC
Upvotes: 1
Reputation: 51137
You need to use HAVING
, not WHERE
.
SELECT user,name,SUM(price)
FROM $tableName
WHERE faktor='1'
GROUP BY user
HAVING SUM(price) < 100
ORDER BY SUM(price) ASC
WHERE
applies before doing the group-by. HAVING
applies afterwords.
Upvotes: 7