我想知道這個查詢是否可以運行得更快,或者如何儘可能地加快查詢速度。如何使這個查詢運行得更快
$result = mysql_query("select
(select count(1) FROM videos WHERE title LIKE '%Cars%')as Cars,
(select count(1) FROM videos WHERE title LIKE '%Bikes%') as 'Bikes',
(select count(1) FROM videos WHERE title LIKE '%Airplanes%') as 'Airplanes',
(select count(1) FROM videos WHERE title LIKE '%Trucks%') as 'Trucks',
(select count(1) FROM videos WHERE title LIKE '%Games%') as 'Games'");
$row = mysql_fetch_assoc($result);
foreach($row as $title => $total)
{
echo '<li>
<a href="search.php?search='. $title . '&submit= ">'. $title.' '. $total .'</a></li>';
}
echo '<li class="spaceIN"></li><li class="letter">A</li>';
我製作了這個腳本的一個副本,並將其粘貼爲100次,這樣做後真的很慢加載。
如果'SELECT'查詢'INSERT' /'UPDATE' /'DELETE'的比例很大,您可以將這些計數器存儲在一個單獨的表中,並在更新'videos'表時更新它們。 – 2014-10-04 17:41:32