title: MSSQL JOIN ON GROUP BY is too slow
body: <p>I have the following query in MSSQL</p>
  
  <pre><code>SELECT TOP 50 CustomerID FROM Ratings
  WHERE CustomerID != 915
  AND MovieID IN (SELECT DISTINCT MovieID FROM Ratings WHERE CustomerID = 915)
  GROUP BY CustomerID
  ORDER BY count(*) DESC
  </code></pre>
  
  <p>It is super fast. When I try to use it in a subquery like this.</p>
  
  <pre><code>SELECT * FROM Ratings
  WHERE MovieID = 1 AND
  CustomerID IN (SELECT TOP 50 CustomerID FROM Ratings
      WHERE CustomerID != 915
      AND MovieID IN (SELECT DISTINCT MovieID FROM Ratings WHERE CustomerID = 915)
      GROUP BY CustomerID
      ORDER BY count(*) DESC)
  </code></pre>
  
  <p>Any ideas on why this is so slow and how I can speed it up? My primary key is (MovieID-CustomerID) and I added a index on CustomerID</p>