Posts: 239
Location: print_r($serbia);
|
Hi,
im stuck here and i don't know how to fix it.
I have a db table which has users ID, user grade and date when someone has voted for that user (3 fields).
Im trying to read the user that has the highest average grade for todays date, limited to one.
But the problem is that i want to read only users that have 5 or more votes.
My query looks like this, but im getting an error:
$query = "SELECT idusers, AVG(votes) AS Grade FROM rank WHERE (data = '{$dbDate}') AND ((SELECT count(ID) + 1 FROM rank) AS tmpcount WHERE tmpcount>4) GROUP BY idusers ORDER BY Grade DESC LIMIT 1";
Red part is where the problem is.
Without the >4 clause this query is working ok, but i need to count the ID's.
Any help?
************************
EDIT:
Nevermind solved it:
$query = "SELECT idusers, AVG(votes) AS Grade FROM rank WHERE (data = '{$dbDate}') GROUP BY idusers HAVING COUNT(ID) > 4 ORDER BY Grade DESC LIMIT 1";
Last edited by miki86; 02-16-2012 at 02:08 PM..
|