Counting sessions - TSQL
As Joe suggested, you should use the LAG() function to compare values to the previous row. It could be implemented like this:

With LaggedLogTime As (
    Select ID, Log_Time,
        PreviousTime = Lag(Log_Time, 1) Over (Partition By ID Order By Log_Time)
      From #log)
Select ID, 
    SessionCount = Sum(iif(DateDiff(Minute, PreviousTime, Log_Time) &gt; 60 Or PreviousTime Is Null, 1, 0))
  From LaggedLogTime
  Group By ID;