title: Get top 'n' records by report_id
body: <p>I have a simple view in my MSSQL database. It consists of the following fields:</p>
  
  <pre><code>report_id INT
  ym VARCHAR -- YYYY-MM
  keyword VARCHAR(MAX)
  visits INT
  </code></pre>
  
  <p>I can easily get the top 10 keyword hits with the following query:</p>
  
  <pre><code>SELECT TOP 10 *
  FROM top_keywords
  WHERE ym BETWEEN '2010-05' AND '2010-05'
  ORDER BY visits DESC
  </code></pre>
  
  <p>Now where it gets tricky is where I have to get the top 10 records for each <code>report_id</code> in the given date range (<code>ym BETWEEN @start_date AND @end_date</code>). </p>
  
  <p>How would I go about getting the top 10 for each report_id? I've stumbled across suggestions involving the use of ROW_NUMBER() and RANK(), but have been vastly unsuccessful in their implementation.</p>