i'm using Hibern8IDE 1.0 to test these querys
i tried what jamstang suggested
Code:
select user, avg(r.score)
from User as user join user.receivedRatings as r
group by user
order by avg(r.score)
and got this error
1 errors occurred while listing (and calling getPathNames).
net.sf.hibernate.JDBCException: Could not execute query
java.sql.SQLException: General error, message from server: "Invalid use of group function"
I also tried
Code:
select user.name, avg(r.score)
from User as user join user.receivedRatings as r
group by user.name
order by avg(r.score)
and got
1 errors occurred while listing (and calling getPathNames).
net.sf.hibernate.JDBCException: Could not execute query
java.sql.SQLException: General error, message from server: "Invalid use of group function"
this is the working SQL that does what I need:
Code:
select user.name as name, avg(r.score) as avgRating
from user, rating as r
where user.id = r.rateeUserId
group by name desc order by avgRating desc limit 10
Code:
mysql> select user.name as name, avg(r.score) as avgRating
-> from user, rating as r
-> where user.id = r.rateeUserId
-> group by name desc order by avgRating desc limit 10 ;
+----------+-----------+
| name | avgRating |
+----------+-----------+
| lagcisco | 8.0000 |
| andy3 | 5.7500 |
+----------+-----------+
2 rows in set (0.03 sec)