title: SQL Group BY, Top N Items for each Group
body: <p>I have a SQL Query which gets gets top 5 sold items at a given store.</p>
  
  <pre><code>SELECT TOP 5 S.UPCCode, SUM(TotalDollarSales) FROM Sales S
  WHERE S.StoreId = 1
  GROUP BY S.UPCCode
  ORDER BY SUM(S.TotalDollarSales) desc
  </code></pre>
  
  <p>The Sales table has -> UPCCode, SaleDate, StoreId, TotalDollarSales</p>
  
  <p>I am looking for a query which will return me Top 5 items sold for each of the stores in a single query. I can write multiple queries and use a union but it doesn't seem efficient.</p>
  
  <p>How can I get the top 5 sold items for each store in a single query.</p>
  
  <p>Thanks in advance.</p>