title: Using SQL DENSE_RANK to determine duplicates
body: <p>Here is an example of the data for which I am trying to find all the orders with same quantities, ignoring the OrderID column</p>
  
  <pre><code>Product     Location      Customer    OrderID    Quantity
   Eggs        Chicago        XYZ        2011        10
   Eggs        Chicago        XYZ        2012        10
   Eggs        Chicago        XYZ        2013        15
  </code></pre>
  
  <p>So, I used DENSE_RANK function in the SQL</p>
  
  <pre><code>Select Product,Location,Customer,OrderID,Quantity,
  Ranking = DENSE_RANK() OVER (PARTITION BY Product,Location,Customer,Quantity
  ORDER BY OrderID ASC)
  FROM MyTable
  </code></pre>
  
  <p>to get the data below</p>
  
  <pre><code>Product     Location      Customer    OrderID    Quantity Ranking
   Eggs        Chicago        XYZ        2011        10       1
   Eggs        Chicago        XYZ        2012        10       2
   Eggs        Chicago        XYZ        2013        15       1
  </code></pre>
  
  <p>So, based on the ranking I was able to filter out the records that have the same quantity across different orderIDs and treat them as one.
  So far everything is good and I am happy. But, one of another crazy requirement is this form of aggregation should be done only for the first change in quantity. For example, if the above data happens to be like one below</p>
  
  <pre><code>Product     Location      Customer    OrderID    Quantity
   Eggs        Chicago        XYZ        2011        10
   Eggs        Chicago        XYZ        2012        10
   Eggs        Chicago        XYZ        2013        15
   Eggs        Chicago        XYZ        2014        15
   Eggs        Chicago        XYZ        2015        15
  </code></pre>
  
  <p>The same SQL would produce result</p>
  
  <pre><code>Product     Location      Customer    OrderID    Quantity Ranking
   Eggs        Chicago        XYZ        2011        10       1
   Eggs        Chicago        XYZ        2012        10       2
   Eggs        Chicago        XYZ        2013        15       1
   Eggs        Chicago        XYZ        2013        15       2
   Eggs        Chicago        XYZ        2013        15       3
  </code></pre>
  
  <p>But, I would need the result to be</p>
  
  <pre><code>Product     Location      Customer    OrderID    Quantity Ranking
   Eggs        Chicago        XYZ        2011        10       1
   Eggs        Chicago        XYZ        2012        10       2
   Eggs        Chicago        XYZ        2013        15       1
   Eggs        Chicago        XYZ        2013        15       1
   Eggs        Chicago        XYZ        2013        15       1
  </code></pre>
  
  <p>Please, note the ranking remains 1 for all the records after the first change in quantity.</p>
  
  <p>Is it possible to tweak my SQL to get the above behavior?</p>
  
  <p>Thanks for any suggestions.</p>