title: Ranking Sql Server Table Rows When a Column Value Changes
body: <p>I have a table in SQL Server like this-</p>
  
  <pre><code>ID  Employee_id  group_field_code   from_date              To_date
  ================================================================================
  1   44855           055            2015-04-01 00:00:00  2015-04-02 17:37:26
  2   44855           055            2015-04-02 17:37:27  2015-04-25 09:31:10
  3   44855           055            2015-04-25 09:31:11  2015-09-18 14:58:59
  4   44855           053            2015-09-18 15:00:00  2016-04-02 02:58:59
  5   44855           055            2016-04-02 03:00:00  2016-05-26 02:58:59
  6   44855           055            2016-05-25 13:25:23  2016-09-07 14:58:59
  7   44855           055            2016-05-26 03:00:00  2016-05-25 13:25:22
  8   44855           052            2016-09-07 15:00:00  2017-05-22 02:58:59
  9   44855           055            2017-05-22 03:00:00  NULL
  </code></pre>
  
  <p>All I want is New Rank for a Row when the group field changes. Like- For ID 1-3 (group_code 55) I want one Rank, for ID 4 (group_Code changes, 53) I want another rank, then again for ID 5 (group_code 5 re-arrives) I want another rank and so on. Is this possible in SQL Server using Rank or other function?  </p>