我有一个“收视率”表,它包含(作为外键)它评级的东西的ID。可能有多个评级,或者没有评级。MySQL表加入AVG()
我想加入表格以查看所有不同ID的不同评分,但现在我无法查看没有评分的事物。例如:
mysql> select avg(ratings.rating), thing.id from ratings, things where ratings.thingId = thing.id group by thing.id;
+----------------------+----+
| avg(ratings.rating) | id |
+----------------------+----+
| 6.3333 | 1 |
| 6.0000 | 2 |
+----------------------+----+
有什么方法可以修改我的选择查询以包含没有评分的ID吗?我试着修改陈述where ratings.thingId = thing.id or thing.id > 0
但这似乎没有帮助。
谢谢并抱歉,如果它不清楚。
当我通过things.id添加组,这起作用 - 谢谢! – JDelonge 2011-02-08 20:08:27