var select = _db.From("Employees")
.SqlJoin(_db.From("Departments"))
.OnColumn("DepartmentId", "Id")
.Root
.SqlGroupBy("Manager")
.ToCursor()
.CountAsc()
.ToSelect()
.SelectGroupBy()
.SelectCount("ManagerCount");
// SELECT [Manager],COUNT(*) AS ManagerCount FROM [Employees] AS t1 INNER JOIN [Departments] AS t2 ON t1.[DepartmentId]=t2.[Id] GROUP BY [Manager] ORDER BY COUNT(*)
5. SelectAggregate
5.1 SelectAggregate方法
聚合筛选
从别名表聚合
GroupByMultiCursorSelect SelectAggregate<TAliasTable>(string tableName, Func<TAliasTable, IAggregateFieldAlias> select)
where TAliasTable : IAliasTable;
GroupByMultiCursorSelect SelectAggregate<TAliasTable>(string tableName, Func<TAliasTable, IEnumerable<IAggregateFieldAlias>> select)
where TAliasTable : IAliasTable;
var select = new CommentAliasTable("c")
.SqlJoin(new PostAliasTable("p"))
.On(c => c.PostId, p => p.Id)
.SqlGroupBy((c, p) => [c.PostId])
.ToCursor(10, 20)
.CountAsc()
.ToSelect()
.SelectGroupBy()
.SelectAggregate<CommentAliasTable>("c", c => c.Pick.SumAs("PickTotal"));
// SELECT c.[PostId],SUM(c.[Pick]) AS PickTotal FROM [Comments] AS c INNER JOIN [Posts] AS p ON c.[PostId]=p.[Id] GROUP BY c.[PostId] ORDER BY COUNT(*) OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY
var select = new CommentTable()
.SqlJoin(new PostTable())
.On(c => c.PostId, p => p.Id)
.SqlGroupBy((c, p) => [c.PostId])
.ToCursor(10, 20)
.CountAsc()
.ToSelect()
.SelectGroupBy()
.SelectAggregate<CommentTable>("Comments", c => c.Pick, Pick => Pick.SumAs("PickTotal"));
// SELECT t1.[PostId],SUM(t1.[Pick]) AS PickTotal FROM [Comments] AS t1 INNER JOIN [Posts] AS t2 ON t1.[PostId]=t2.[Id] GROUP BY t1.[PostId] ORDER BY COUNT(*) OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY