Irwsoft Data Framework

Group and Having syntaxes
Brief Information
EditionsAll Editions
TopicsUsing group syntax and having syntax.

This sample will show how to group records and set having condition in select query.

Example : We want to display total members of each leader which LeaderID between 1 and 10 in Person table.

     SELECT COUNT(P1.LeaderID) FROM PERSON P1 GROUP BY P1.LeaderID HAVING P1.LeaderID BETWEEN 1 AND 10

C# code
PersonTable person = new PersonTable();

SqlSelectFrom select = new SqlSelectFrom(person);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection.

select.ConnectionString = "...";  // [OPTIONAL]

// display LeaderId then group it later
select.Column(person.LeaderId);

// display Count of LeaderId
select.Columns.Count(person.LeaderId);

// group by person.LeaderId
select.Group.By(person.LeaderId);

// LeaderId between 1 and 10
select.Group.Having.Between(person.LeaderId, 1, 10);

// Execute the query
Irwsoft.Data.DataView dv = select.Execute();
Irwsoft Data Ultimate Edition provides comprehensive features of Irwsoft Data Framework and support from irwsoft.