title: How to get x top results for each year SQLite
body: <p>I've got a problem with my solution, I found this example:</p>
  
  <pre><code>(SELECT COUNT(*) FROM person AS b    
  WHERE b.group = a.group AND b.age &gt;= a.age) &lt;= 2    
  ORDER BY a.group ASC, a.age DESC
  </code></pre>
  
  <p>(from: <a href="https://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results">Get top n records for each group of grouped results</a>)</p>
  
  <p>But I need to create new column based on a old one, so I need to make some calculation and when I'm trying to add something more I'm getting an error messages. 
  If I simply add eaquations, it's ok, for example:</p>
  
  <pre><code>(SELECT COUNT(*) FROM person AS b   
  WHERE b.group = a.group AND b.age*100 &gt;= a.age*100) &lt;= 2   
  ORDER BY a.group ASC, a.age DESC   
  </code></pre>
  
  <p>But when I'm trying to rename my new column, there is too many AS.</p>
  
  <p>I also tried to use UNION ALL, but my SQLite is not happy with (). This is not working for me at all:   </p>
  
  <pre><code>(   
    select *     
    from mytable    
    where `year` = 2012   
    order by score*100/50 AS percent desc   
    LIMIT 2   
  )   
  UNION ALL   
  (   
    select *   
    from mytable    
    where `year` = 2013   
    order by score*100/50 AS percent desc   
    LIMIT 2   
  )   
  </code></pre>
  
  <blockquote>
    <p>"Result: near "(": syntax error<br>
    At line 1:<br>
    ("   </p>
  </blockquote>
  
  <p>Even when I'm taking out SELECT and FROM befor the (), I'm getting the error message.   </p>
  
  <pre><code>select * from mytable   
  (where `year` = 2012   
    order by score*100/50 AS percent desc   
    LIMIT 2)   
  
  UNION ALL   
  
  select * from mytable    
  (where `year` = 2013   
    order by score*100/50 AS percent desc   
    LIMIT 2)   
  </code></pre>
  
  <blockquote>
    <p>near "WHERE": syntax error</p>
  </blockquote>
  
  <p>Can please someone explain me why?</p>
  
  <p><strong>EDIT</strong>   </p>
  
  <p>Here is the data.   </p>
  
  <pre>| Person | Year  | Score |   
  +--------+-------+-------+
  | Bob    | 2013  | 32    |   
  | Jill   | 2012  | 34    |   
  | Shawn  | 2012  | 42    |   
  | Jake   | 2012  | 29    |   
  | Paul   | 2013  | 36    |   
  | Laura  | 2013  | 39    |</pre>
  
  <p>Desired result set:    </p>
  
  <pre>| Person | Year  | Percent |    
  +--------+-------+---------+   
  | Shawn  | 2012  | 84      |   
  | Jill   | 2012  | 68      |   
  | Laura  | 2013  | 78      |   
  | Paul   | 2013  | 72      |   
  +--------+-------+---------+</pre>
  
  <p>where percent = score*100/50</p>