title: SQL Partition By Multiple Columns
body: <p>I have following GPS report table :</p>
  
  <p><img src="https://i.stack.imgur.com/fublb.png" alt="Original Table"></p>
  
  <p>I'm expecting to group it by Lat, Long and retrieve the sequence of the resource movement :</p>
  
  <p><img src="https://i.stack.imgur.com/jyMen.png" alt="Expected Result"></p>
  
  <p>I'm almost there with following code :</p>
  
  <pre><code>  ;WITH dt AS(
    SELECT ROW_NUMBER() OVER (Partition By ROUND(Latitude,2), ROUND(Longitude, 2),         DATEPART(hh,[GPS Time])  ORDER BY [GPS Time]) AS RowNumber,  
   ID, ResourceID, Region, [GPS Time], ROUND(Latitude,2) AS Latitude, ROUND(Longitude, 2) AS Longitude 
   FROM [dbo].[GeofenceReport] WHERE TenantID=2 AND CAST([GPS Time] AS Date) = '2014-02-11' AND ResourceID = 'MH202 (B 9349 OI)'
  )
    SELECT * FROM dt WHERE RowNumber = 1 ORDER BY [GPS Time] 
  </code></pre>
  
  <p>But this will group all occurrence of the resource. I want it to group by sequence. So if resource leaves location A - moves to Location B - then Location C and then Location A again. </p>
  
  <p><a href="http://sqlfiddle.com/#!6/07309/1" rel="nofollow noreferrer">Example in SQL Fiddle</a> </p>