p*****u 发帖数: 310 | 1 请教以下SQL如何优化。我已经斗争了一天了,实在不太懂。其实就是一个很大的表要
left join 一个小表。所有相关的列都index了。不胜感谢。
select
report.type,
report.categoryId,
max(report.submitTime) as submitTime,
count(report.categoryId) as occurrences,
category.description
from
77_report report
LEFT JOIN
categoryinfo category ON category.categoryid = report.categoryid
AND category.skuid = 77
where
1 = 1
and report.submitTime > (CURDATE() - INTERVAL 7 DAY)
group by categoryId
order by submitTime desc; |
|