title: How do I group only the last `n` rows?
body: <p>Take the following table:</p>
  
  <pre><code>id - member_id - day
  
  0      1         1
  1      1         1
  2      1         2
  3      2         2
  4      1         3
  5      2         3
  6      2         3
  7      1         3
  8      1         3
  9      2         3
  </code></pre>
  
  <p>Lets say I want to do something like:</p>
  
  <pre><code>SELECT `day`,
      COUNT(`id`) AS `count`
  FROM `table`
  WHERE `member_id` = 1
  GROUP BY `day`
  ORDER BY `day` DESC
  LIMIT 5
  </code></pre>
  
  <p>and I expected a result like:</p>
  
  <pre><code>day - count
  3     3
  2     1
  1     1
  </code></pre>
  
  <p>Note how the count for day 1 is cut in half, as only the most recent five rows for that member are grouped. Instead, I get the last five groups, ordered by day.</p>
  
  <p>How do I group only the most recent <em>n</em> rows with a WHERE condition?</p>
  
  <p>Effectively, I want to use WHERE, then LIMIT, and only then GROUP.</p>