-
Notifications
You must be signed in to change notification settings - Fork 455
Aggregate query
shuxin edited this page Jan 29, 2023
·
2 revisions
Chloe 可以像写 sql 一样实现聚合查询。
IQuery<Person> q = dbContext.Query<Person>();
//注:一定要 ToList()
q.Select(a => Sql.Count()).ToList().First();
/*
* SELECT COUNT(1) AS [C] FROM [Person] AS [Person]
*/
/* 支持多个聚合函数 */
q.Select(a => new
{
Count = Sql.Count(),
LongCount = Sql.LongCount(),
Sum = Sql.Sum(a.Age),
Max = Sql.Max(a.Age),
Min = Sql.Min(a.Age),
Average = Sql.Average(a.Age)
}).ToList().First();
/*
* SELECT COUNT(1) AS [Count],COUNT_BIG(1) AS [LongCount],CAST(SUM([Person].[Age]) AS INT) AS [Sum],MAX([Person].[Age]) AS [Max],MIN([Person].[Age]) AS [Min],CAST(AVG([Person].[Age]) AS FLOAT) AS [Average]
FROM [Person] AS [Person]
*/
var count = q.Count();
/*
* SELECT COUNT(1) AS [C] FROM [Person] AS [Person]
*/
var longCount = q.LongCount();
/*
* SELECT COUNT_BIG(1) AS [C] FROM [Person] AS [Person]
*/
var sum = q.Sum(a => a.Age);
/*
* SELECT CAST(SUM([Person].[Age]) AS INT) AS [C] FROM [Person] AS [Person]
*/
var max = q.Max(a => a.Age);
/*
* SELECT MAX([Person].[Age]) AS [C] FROM [Person] AS [Person]
*/
var min = q.Min(a => a.Age);
/*
* SELECT MIN([Person].[Age]) AS [C] FROM [Person] AS [Person]
*/
var avg = q.Average(a => a.Age);
/*
* SELECT CAST(AVG([Person].[Age]) AS FLOAT) AS [C] FROM [Person] AS [Person]
*/
熬夜的时候容易引起脱发,熬夜时人的免疫力会下降,还会引起内分泌的变化,导致皮脂分泌增多,这些因素都不利于头发的生长,有可能引起脱发。如果出现熬夜脱发的情况,需要及时纠正日常的生活习惯,合理安排休息时间,早睡早起,适当的锻炼身体,多进食优质的蛋白质,增强身体的抵抗力,促进头发的生长。
发量有限,远离996!!!