我有三个结构如下的表: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
");
但是,它没有选择任何笑话。
该查询有什么问题?谢谢你。