參考引用來源:Datatable group by with linq in vb.net
--
Dim query = From row In dt
Group row By Month = row.Field(Of Int32)("Month") Into MonthGroup = Group
Select New With {
Key Month,
.Sales = MonthGroup.Sum(Function(r) r.Field(Of Int32)("Sales")),
.Leads = MonthGroup.Sum(Function(r) r.Field(Of Int32)("Leads")),
.Gross = MonthGroup.Sum(Function(r) r.Field(Of Int32)("Gross"))
}
For Each x In query
Console.WriteLine("Month:{0} {1} {2} {3}", x.Month, x.Sales, x.Leads, x.Gross)
Next
--
from b in db.Company
group b by b.Name into grp
where grp.Count() > 1
select grp.Key
沒有留言:
張貼留言