我目前正在运行此查询,加载需要大约15秒才能优化查询
SELECT *, `points`.`players` as `players` ,
FROM_UNIXTIME(`points`.`timestamp`, '%Y-%m-%d %H:%i') as `date`,
(SELECT `points`.`players`
FROM `points`
WHERE FROM_UNIXTIME(`points`.`timestamp`, '%Y-%m-%d %H:%i') > `date` - INTERVAL 7 DAY
AND FROM_UNIXTIME(`points`.`timestamp`, '%Y-%m-%d %H:%i') < `date` - INTERVAL 167 HOUR
AND `server_id` = {$server_id}
AND `type` = 2
LIMIT 1
) as `prevplayers`
FROM `points`
WHERE `points`.`timestamp` > UNIX_TIMESTAMP(NOW() - INTERVAL 7 DAY)
AND `server_id` = {$server_id}
AND `type`=2
GROUP BY DATE_FORMAT(FROM_UNIXTIME(`points`.`timestamp`), '%Y-%m-%d %H')
ORDER BY DATE_FORMAT(FROM_UNIXTIME(`points`.`timestamp`),'%Y-%m-%d %H')
表格结构
理想时间是1-2秒
任何建议?
由于 Somdeb
答案 0 :(得分:1)
您可以按照以下顺序创建包含列的附加索引并重试查询吗?