我有这个有效的 sql 搜索查询,但它只有在投票表中存在投票时才有效。
mysql_query("SELECT m.Title, r.Subject, SUM(v.IsGood) AS Good, SUM(v.IsBad) AS Bad
FROM Movies m
JOIN Reviews r
ON m.ID=r.MovieID
JOIN Votes v
ON r.ID=v.ReviewID
WHERE (m.Title LIKE '%" . $search . "%' OR r.Subject LIKE '%" . $search . "%')
GROUP BY m.Title, r.Subject
ORDER BY SUM(v.IsGood) DESC, SUM(v.IsBad) ASC LIMIT 10")
因此,我将其更改为下面的内容,这样无论是否有 0 票,它仍应显示。但它没有任何结果,谁能告诉我我做错了什么?
mysql_query("SELECT m.Title, r.Subject, COUNT(v.ReviewID) AS Rvotes, SUM(v.IsGood) AS Good, SUM(v.IsBad) AS Bad
FROM Movies m
JOIN Reviews r
ON m.ID=r.MovieID
JOIN Votes v
ON r.ID=v.ReviewID
WHERE (m.Title LIKE '%" . $search . "%' OR r.Subject LIKE '%" . $search . "%')
GROUP BY m.Title, r.Subject, v.ReviewID
HAVING Rvotes >= 0
ORDER BY SUM(v.IsGood) DESC, SUM(v.IsBad) ASC LIMIT 10")