title: How to fetch top n records for each category
body: <p>I have a table like below, placed at <a href="http://sqlfiddle.com/#!2/b8330/8" rel="nofollow noreferrer">SQL FIDDLE</a></p>
  
  <pre><code>id  empid proj  file  rating
  ~~  ~~~~~ ~~~~  ~~~~  ~~~~~~
  1   1863   G1   file1    1
  2   P4645  G1   file2    1
  3   P6682  G1   file3    1
  4   P6682  G1   file4    1
  5   P4645  G1   file5    1
  6   P4645  G1   file6    1
  7   1863   G1   file7    1
  8   1863   G1   file8    1
  9   1863   G1   file19   1
  10  P6682  G2   file21   1
  11  1863   G2   file55   1
  12  P6682  G2   file60   1
  13  P4645  G2   file85   1
  14  P6682  G2   file91   1
  15  P4645  G2   file93   1
  16  P4645  G3   file95   1
  17  P4645  G3   file100  1
  18  P4645  G3   file125  1
  19  1863   G3   file131  1
  20  1863   G3   file150  1
  21  P6682  G3   file193  1
  21  P6682  G3   file193  1
  </code></pre>
  
  <p>I need an SQL to retrieve top n (say top 2) ratings count from the above table for each category (proj)</p>
  
  <p>Desired OP as below</p>
  
  <pre><code>proj  empid  ratings
  ~~~~  ~~~~~  ~~~~~~~
   G1   1863      4
   G1   P4645     3
   G2   P6682     3
   G2   P4645     2
   G3   P4645     3
   G3   1863      2
   G3   P6682     2
  </code></pre>
  
  <p>Tried to follow the meathod in this <a href="https://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results">thread</a> but could not achive from the table desing i have.</p>