Suppose you have the following SQL statement:
select sum(A), max(B), avg(C) from TBL group by D
Try this in C#:
from t in table
group t by D
into g
select new {
s = g.Sum(x => x.A),
m = g.Max(x => x.B),
a = g.Average(x => x.C)
}
-- or in VB: --
from t in TBL
group t by key = D
into g = group
select s = g.Sum(function(x) x.A),
m = g.Max(function(x) x.B),
a = g.Average(function(x) x.C)
The obvious, which in VB would be:
aggregate t in TBL into s = Sum(t.A), m = Max(t.B), a = Average(t.C)
though it will give the same results, it has a higher cost as it issues multiple SQL select statements, one for each aggregate function, i.e. it will run in multiple passes. The first syntax, gives a single (fairly complex, but efficient) SQL statement which does a single pass against the database.
PS. If you don't have a key by which to group by (i.e. you need a single row as the result, covering the whole data set), use a constant as in:
from t in TBL
group t by key = 0
into g = group
select s = g.Sum(function(x) x.A),
m = g.Max(function(x) x.B),
a = g.Average(function(x) x.C)