okay so i have one database with three columns: id, username, and rating.
The database would look like this:
------------ ------------ ------------
| ID | NAME | RATING |
------------ ------------ ------------
| 1 | bc112 | 3 |
------------ ------------ ------------
| 2 | cd111 | 1 |
------------ ------------ ------------
| 2 | cd111 | 2 |
------------ ------------ ------------
| 2 | cd111 | 6 |
------------ ------------ ------------
So basically where I am stuck is how do I get the average rating for each specific user?
I tried this:
SELECT ID, RATING
FROM THING
WHERE AVG(RATING) FOR ID < 3;
But the result is showing me nothing. What is wrong with the code?
By using
AVGaggregate function,group byclause andhavingclause as follows: