title: Spark sql top n per group
body: <p>How can I get the top-n (lets say top 10 or top 3) per group in <code>spark-sql</code>?</p>
  
  <p><a href="http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/" rel="noreferrer">http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/</a> provides a tutorial for general SQL. However, spark does not implement subqueries in the where clause.</p>