title: MySQL Query (with subquery) optimization
body: <p>I'm having trouble figuring how to speed up the query below.</p>
  
  <pre><code>SELECT 
  (SELECT SUM(pi2.OperationMW) FROM projectsimport pi2 
      WHERE pi2.CommissionYear  &lt;=  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 &gt; 1993 
  AND CommissionYear &lt;= 2018 
  AND CommissionYear IS NOT NULL    
  GROUP BY TurbineOEM, CommissionYear 
  Order by TurbineOEM, CommissionYear
  </code></pre>
  
  <p>Running explain gives me the following results:</p>
  
  <p><a href="https://i.stack.imgur.com/0DE1L.jpg" rel="nofollow noreferrer">explain results</a></p>
  
  <p>I feel like I'm missing something pretty obvious but any help would be appreciated</p>