Having and groupby

Category:
TypeProviders.SqlDataConnection
Description: Use having and groupby clause
Code:

type T0 = Microsoft.FSharp.Data.TypeProviders.SqlDataConnection< "Data Source=localhost;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234" >

let TypeProvider15() =
let db = T0.GetDataContext();
let q = query {
for n in db.Student do
groupBy n.Age into g
where (g.Count()>1)
select (g.Key, g.Count())
}
q |> Seq.iter (fun (key, count) -> printfn "key=%A count=%d" key count)

Execution Result:
key=20 count=2
key=21 count=2
key=22 count=3

Last edited Mar 1, 2012 at 7:03 PM by ttliu2000, version 2

Comments

No comments yet.