title: Cumulative counts for distinct sequence encounters
body: <p>I have the following structure</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE t (
      entry int,
      mode int,
      device_id int,
    );
    
  INSERT INTO t (entry, mode, device_id)
  VALUES 
  (0, 0, 0), 
  (1, 1, 0), -- mode 1 count+1
  (2, 1, 0),
  (3, 2, 0),
  (4, 1, 0), -- mode 1 count+1
  (5, 0, 0),
  
  (0, 0, 1),
  (1, 2, 1), -- mode 2 count+1
  (2, 0, 1),
  (3, 2, 1), -- mode 2 count+1
  (4, 2, 1),
  (5, 0, 1);
  </code></pre>
  <p>And I would like a cumulative count of when a certain mode was used by a device. Counting mode 1 for device 0 should yield the values</p>
  <p><code>0, 1, 1, 1, 2, 2</code></p>
  <p>Because the counter doesn't increment on repeat values (i.e. the mode didn't change).</p>
  <p>Similarly, counting mode 2 for device 1 should yield</p>
  <p><code>0, 1, 1, 2, 2, 2</code></p>
  <p>as 2 distinct changes to this mode are observed.</p>
  <p>How would I do this in MS SQL?</p>