The GroupBy extension method returns an IEnumerable(Of IGrouping(Of TKey,TSource), each IGrouping represents a collection of items and exposes a Key
property which in this case will be the date. You can apply a Select to project the groupings and apply Min and Max aggregates to the items, e.g. (Note: as I don't have the database I've set up some example data for the query result):
Structure Item
Public DateTime As DateTime
Public Temp As Double
End Structure
Sub Main()
' Test data
Dim query = {
New Item With {.DateTime = #12/1/2013 00:00#, .Temp = 2},
New Item With {.DateTime = #12/1/2013 01:00#, .Temp = 2},
New Item With {.DateTime = #12/1/2013 02:00#, .Temp = 2},
New Item With {.DateTime = #12/1/2013 03:00#, .Temp = 1.7},
New Item With {.DateTime = #12/1/2013 04:00#, .Temp = 2},
New Item With {.DateTime = #12/1/2013 05:00#, .Temp = 2},
New Item With {.DateTime = #12/1/2013 06:00#, .Temp = 2.2}
}
' Aggregate with extension methods
Dim aggregated =
query.GroupBy(Function(item) item.DateTime.Date) _
.Select(Function(grouping) _
New With {
.DateTime = grouping.Key,
.Max = grouping.Max(Function(item) item.Temp),
.Min = grouping.Min(Function(item) item.Temp)
})
' Aggregate with sugared LINQ
Dim aggregated2 =
From item In query
Group item By key = item.DateTime.Date Into Group
Select New With {
.DateTime = key,
.Min = Group.Min(Function(item) item.Temp),
.Max = Group.Max(Function(item) item.Temp)}
' Show aggregated results
For Each item In aggregated2
Console.WriteLine(item.DateTime & " " & item.Min & " " & item.Max)
Next
End Sub
For reference check out the LINQ Query Samples - Grouping Operators