I have three tables that are structured like this: http://i41.tinypic.com/2bt9aq.png
我想要做的是检索某个分类下所有笑话的笑话ID、标题和平均评级,并按字母顺序排序。我有这个查询:
$result = mysql_query("
SELECT jokedata.id AS joke_id,
jokedata.joketitle AS joke_title,
SUM(ratings.rating) / COUNT(ratings.rating) AS average
FROM jokedata
INNER JOIN ratings ON ratings.content_type = joke AND ratings.relative_id = jokedata.id
WHERE jokecategory = $cur_category
GROUP BY jokedata.id
ORDER BY jokedata.joketitle
LIMIT $offset, $jokes_per_page
");
然而它并没有选择任何笑话。
那个查询有什么问题?谢谢。