title: Top 10 products for dates between
body: <p>I'm trying to figure out the better way of creating a single query that will produce a result with top 10 products for each date. I have a row with two columns - <code>PID (int)</code> and <code>EventDate (date)</code>, a row for each click.</p>
  
  <p>Can you suggest how I can get the result with Top 10 products clicked on for a date range? I'm getting stuck on understanding how the sub-query must be constructed. I can only get the part with group by date, but then my mind gets stuck on count() and aggregation issues.</p>
  
  <p>Here's my query for an individual date, but I want to have to for a range of dates. I can, of course, do sub-query by generating event dates, but want to figure out how to do it more elegantly.</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT TOP 10 COUNT() as count, PID
  FROM view_product
  WHERE EventDate = toDate('2020-05-11')
  GROUP BY PID
  ORDER BY count DESC
  </code></pre>
  
  <p>The expected output is something like this:</p>
  
  <pre class="lang-bash prettyprint-override"><code>PID Count Date
  1   123   2020-02-04
  21  101   2020-02-04
  1332 99   2020-02-04
  11   51   2020-02-04
  634  49   2020-02-04
  1332 43   2020-02-04
  1   24   2020-02-04
  21  23   2020-02-04
  1332 6   2020-02-04
  11   3   2020-02-04
  
  1   266   2020-02-02
  21  241   2020-02-02
  1332 232   2020-02-02
  11   179   2020-02-02
  634  163   2020-02-02
  1332 159   2020-02-02
  1   144   2020-02-02
  21  100   2020-02-02
  1332 99   2020-02-02
  11   74   2020-02-02
  </code></pre>