SELECT s.topic_id FROM ( SELECT s.topic_id, COUNT(*) AS count FROM ( SELECT DISTINCT s.topic_id, s.ec_id FROM log_stat AS s ORDER BY s.stat_date DESC LIMIT 5000 ) AS s GROUP BY s.topic_id ORDER BY count DESC LIMIT 0, 6 ) AS s INNER JOIN cont_topic as t ON t.topic_id = s.topic_id WHERE 1=1 AND t.topic_view=1 AND t.topic_date_create <= NOW() GROUP BY s.topic_id ORDER BY s.count DESC LIMIT 0, 6