Как запросить groupby в следующей ситуации
У меня есть datatable в следующем формате
Id LocationId UserName Startdate 1 10 xz 2017-02-21 09:05:20 2 10 xz 2017-02-21 09:15:20 3 10 xz 2017-02-21 09:25:20 4 10 xz 2017-02-21 09:35:20 5 11 xz 2017-02-21 09:45:20 6 11 xz 2017-02-21 09:55:20 7 11 xz 2017-02-21 10:05:20 8 11 xz 2017-02-21 10:15:20
Я хочу вычислить время начала и окончания и разницу во времени ,
и есть показать запись как
Id locationId startdate starttime endtime timespan 1 10 2017-02-21 09:05 09:35:20 0hr 30min0sec 1 10 2017-02-21 09:05 09:35:20 0hr 30min0sec
Что я уже пробовал:
<pre> If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then hdnreviewerHistoryCount.Value = UserManager.GetReviewerHistoryByActivityTypeCount(Request.QueryString("Id"), StartDate, EndDate, activity) Dim StartTime As New TimeSpan Dim EndTime As New TimeSpan Dim totalTime As New TimeSpan totalTime = Convert.ToDateTime(dt.Rows(dt.Rows.Count - 1)("AddedOn")).Subtract(dt.Rows(0)("AddedOn")) Dim index As Integer = 0 Dim filterdata As New Filterdata Dim prevTime As New DateTime Dim prevLocation As Integer For Each row As DataRow In dt.Rows If index = 0 AndAlso row("CheckInLocation") IsNot DBNull.Value Then prevTime = row("AddedOn") prevLocation = row("CheckInLocation") Else If prevLocation = row("CheckInLocation") Then Dim timeDiff As TimeSpan = Convert.ToDateTime(row("AddedOn")).Subtract(prevTime) EndTime = EndTime.Add(timeDiff) prevLocation = IIf(row("LocationAddress") Is DBNull.Value, 0, row("LocationAddress")) prevTime = row("AddedOn") Else End If End If index += 1 Next rptreviewerhistory.DataSource = filterlist rptreviewerhistory.DataBind() End If End Sub Public Class Filterdata Public Property customdate As DateTime Public Property fromdate As DateTime Public Property todate As DateTime Public Property timespent As DateTime Public Property LocationName As String End Class