我无法确定如何加快下面的查询速度。
SELECT
(SELECT SUM(pi2.OperationMW) FROM projectsimport pi2
WHERE pi2.CommissionYear <= pi.CommissionYear
AND pi2.TurbineOEM = pi.TurbineOEM
AND pi2.Country = 'US' ) as y,
TurbineOEM as Name , CommissionYear
FROM projectsimport pi
WHERE TurbineOEM != '' AND Country = 'US'
AND CommissionYear > 1993
AND CommissionYear <= 2018
AND CommissionYear IS NOT NULL
GROUP BY TurbineOEM, CommissionYear
Order by TurbineOEM, CommissionYear
运行说明给出了以下结果:
我觉得我错过了一些非常明显的东西,但任何帮助都会受到赞赏
答案 0 :(得分:0)
projectsimport
的综合索引:
INDEX(Country, TurbineOEM, CommissionYear, OperationMW)
INDEX(Country, CommissionYear, TurbineOEM)