分组查询

2021-11-3 查询 小于 1 分钟

# 支持group

    var ids = new[] {"200", "300"};
            var dateOfMonths = new[] {202111, 202110};
            var group = await (from u in _virtualDbContext.Set<SysUserSalary>()
                    .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
                group u by new
                {
                    UId = u.UserId
                }
                into g
                select new
                {
                    GroupUserId = g.Key.UId,
                    Count = g.Count(),
                    TotalSalary = g.Sum(o => o.Salary),
                    AvgSalary = g.Average(o => o.Salary),
                    AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
                    MinSalary = g.Min(o => o.Salary),
                    MaxSalary = g.Max(o => o.Salary)
                }).ToListAsync();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
聚合函数 是否支持
Count 支持
Sum 支持
Max 支持
Min 支持
Average 支持
上次编辑于: 2021年11月15日 16:23
贡献者: xuejiaming