Reputation: 1985
My Data is set out like this:
-------------------------------
|id|name|vote_count|vote_score|
|1 |Jim |9 |14 |
|2 |Bert|8 |17 |
|3 |Bob |43 |45 |
|4 |Will|1 |5 |
-------------------------------
You can work out a users score by doing this:
$score = round($result['vote_score'] / $result['vote_count'], 2);
Is there an SQL query I can do to only get users with a score of 3 or more?
Upvotes: 0
Views: 261
Reputation: 1318
How about -
SELECT
id,
name,
vote_count,
vote_score,
vote_score / vote_count as score
FROM
tablename
WHERE
vote_score / vote_count >= 3;
Upvotes: 1
Reputation: 4616
SELECT * FROM users WHERE ROUND((vote_score / vote_count),2) >= 3
Upvotes: 3
Reputation: 4614
You mean:
select * from users where round(vote_score / vote_count, 2) >= 3;
?
Upvotes: 3