title: SQL - Use dense_rank and group by together
body: <p>I was under the impression that when we use rank/row_number/dense_rank, we can NOT use group by, but why does below logic run successfully</p>
  
  <pre><code>Select product, type, dense_rank() over (partition by type order by sum(sales) desc) as rnk 
  From mytable 
  Where date&gt; dateadd(month, -3, getdate()) 
  Group by product, type
  </code></pre>
  
  <p>Why am I able to order by sum(sales) within the rank function?</p>
  
  <p>Thanks</p>