-
Notifications
You must be signed in to change notification settings - Fork 455
Group query
shuxin edited this page Jun 10, 2023
·
5 revisions
Chloe 支持分组查询以及分组后 Having 过滤和聚合查询。
IQuery<Person> q = dbContext.Query<Person>();
//用法1
IGroupingQuery<Person> g = q.Where(a => a.Id > 0).GroupBy(a => a.Age);
// g = g.AndBy(a => a.Id); //多个字段分组
g = g.Having(a => a.Age > 1 && Sql.Count() > 0);
g.Select(a => new
{
a.Age,
Count = Sql.Count(),
Sum = Sql.Sum(a.Age),
Max = Sql.Max(a.Age),
Min = Sql.Min(a.Age),
Avg = Sql.Average(a.Age)
}).ToList();
/*
* SELECT [Person].[Age] AS [Age],COUNT(1) AS [Count],CAST(SUM([Person].[Age]) AS INTEGER) AS [Sum],CAST(MAX([Person].[Age]) AS INTEGER) AS [Max],CAST(MIN([Person].[Age]) AS INTEGER) AS [Min],CAST(AVG([Person].[Age]) AS REAL) AS [Avg]
* FROM [Person] AS [Person] WHERE [Person].[Id] > 0
* GROUP BY [Person].[Age] HAVING ([Person].[Age] > 1 AND COUNT(1) > 0)
*/
//用法2:匿名类方式根据多个字段分组
g = q.Where(a => a.Id > 0).GroupBy(a => new { a.Age, a.Id });
g = g.Having(a => a.Age > 1 && Sql.Count() > 0);
g.Select(a => new { a.Age, Count = Sql.Count(), Sum = Sql.Sum(a.Age), Max = Sql.Max(a.Age), Min = Sql.Min(a.Age), Avg = Sql.Average(a.Age) }).ToList();
/*
* SELECT [Person].[Age] AS [Age],COUNT(1) AS [Count],CAST(SUM([Person].[Age]) AS INTEGER) AS [Sum],MAX([Person].[Age]) AS [Max],MIN([Person].[Age]) AS [Min],CAST(AVG([Person].[Age]) AS REAL) AS [Avg]
* FROM [Person] AS [Person] WHERE [Person].[Id] > 0
* GROUP BY [Person].[Age],[Person].[Id] HAVING ([Person].[Age] > 1 AND COUNT(1) > 0)
*/
熬夜的时候容易引起脱发,熬夜时人的免疫力会下降,还会引起内分泌的变化,导致皮脂分泌增多,这些因素都不利于头发的生长,有可能引起脱发。如果出现熬夜脱发的情况,需要及时纠正日常的生活习惯,合理安排休息时间,早睡早起,适当的锻炼身体,多进食优质的蛋白质,增强身体的抵抗力,促进头发的生长。
发量有限,远离996!!!