0
我有一個php文件查詢mySql數據庫設置與一個表上的電影和另一個movieRatings。我想要統計一部特定電影的「五星級」,「四星級」等評級數量。我的查詢很有效,但是速度非常慢,因爲我意識到它會通過整個movieRatings表格5次查看我想要查看的每部電影。在電影數據庫上極慢的mySQL查詢
我的查詢:
$sql = "SELECT *
FROM MOVIE_INFO,
(SELECT count(ratingValue) as star5 FROM MOVIE_RATINGS2 WHERE itemID=$b[0] AND ratingValue = 5) SUB,
(SELECT count(ratingValue) as star4 FROM MOVIE_RATINGS2 WHERE itemID=$b[0] AND ratingValue = 4) SUB1,
(SELECT count(ratingValue) as star3 FROM MOVIE_RATINGS2 WHERE itemID=$b[0] AND ratingValue = 3) SUB2,
(SELECT count(ratingValue) as star2 FROM MOVIE_RATINGS2 WHERE itemID=$b[0] AND ratingValue = 2) SUB3,
(SELECT count(ratingValue) as star1 FROM MOVIE_RATINGS2 WHERE itemID=$b[0] AND ratingValue = 1) SUB4
WHERE movieID = $b[0]";
我想如果我可以從該特定影片的影片收視率一度拉子集,它會加速它的巨大的,但我不記得如何做到這一點。
完美,謝謝! – 2013-04-27 08:06:47
很高興幫助。不要忘記接受答案:-) – 2013-04-28 16:49:57