0

此查询从两个单独的表中提取。video_thumb_chosen 有一个拇指列,需要在哪里选择模式值。

$query = "SELECT DISTINCT videos.VIDEOID, 
                          videos.title,
                          (
                           select video_thumb_chosen.thumb
                           from video_thumb_chosen
                           where video_thumb_chosen.videoid = videos.VIDEOID 
                           group by video_thumb_chosen.thumb
                           order by count(video_thumb_chosen.thumb) desc limit 1 
                          ) as thumb, 
                          videos.rating, 
                          videos.runtime, 
                          videos.viewcount, 
                          videos.public, 
                          videos.time_added, 
                          videos.HD 
          FROM videos,video_thumb_chosen 
          WHERE videos.active='1' 
             && videos.tube=0  
             && videos.categories <> 7 
          ORDER BY videos.last_viewed desc limit $config[max_viewing_now]"; 
4

1 回答 1

1

删除子句中的交叉连接from将有助于:

FROM videos

您没有在外部查询中使用 video_thumb_chosen,因此没有理由包含它。

可能还有其他优化。

鉴于您在 MySQL 中所做的事情,这可能会解决问题。这是查询:

SELECT videos.VIDEOID, videos.title,
      (select video_thumb_chosen.thumb
       from video_thumb_chosen
       where video_thumb_chosen.videoid = videos.VIDEOID
       group by video_thumb_chosen.thumb
       order by count(video_thumb_chosen.thumb) desc limit 1
      ) as thumb,
      videos.rating, videos.runtime, videos.viewcount, videos.public, videos.time_added, videos.HD
FROM videos
where  videos.active='1' && videos.tube=0  && videos.categories <> 7
ORDER BY videos.last_viewed
desc limit $config[max_viewing_now]"; 
于 2012-12-13T15:49:54.697 回答