多表关联进行分组报错;Expression #1 of SELECT list is not in GROUP BY c 返回

报错内容:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'robot.a.Id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
代码:
var result = await _robotServices.Db.Queryable<RobotReport>()
.LeftJoin<Robots>((a, b) => a.robot_model_md5 == b.model_md5)
.InnerJoin<RobotReportBasicInfo>((a, b, c) => a.uuid == c.robot_report_uuid)
.InnerJoin<RobotReportRbkreport>((a, b, c, d) => a.uuid == d.robot_report_uuid)
.InnerJoin<RobotReportUndispatchableReason>((a, b, c, d, e) => a.uuid == e.robot_report_uuid)
.LeftJoin<RobotReportRbkreportDIorDO>((a, b, c, d, e, f) => a.uuid == f.robot_report_uuid)
.OrderBy((a,b)=>b.CreateTime,OrderByType.Desc)
.GroupBy(a => a.uuid)
.Select((a, b, c, d, e,f) => new RobotDto()
{
Id = a.Id.ToString(),
Name = a.vehicle_id,
Ip = c.ip,
Group = c.current_group,
//IOList = SqlFunc.Subqueryable<RobotReportRbkreportDIorDO>().ToList(),
//IO =new IODto(){ DIorDOId = f.DIorDOId, dido_type = f.dido_type, status = f.status },
//IO= new List<RobotReportRbkreportDIorDO> { f },
Tags = c.current_label,
Status = e.dispatchable_status,
//CurrentOrder = a.current_order,
//OrderStatus = a.order_status,
IsEmergencyStopped = d.emergency,
IsSoftEmergencyStopped = d.soft_emc,
Battery = d.battery_level*100,
Confidence = d.confidence,
Control = e.unlock,
LocationStatus = d.reloc_status,
NavigationStatus = d.task_status,
Map = c.current_map,
Model = c.model,
DeviceId = a.uuid,
})
.ToPageListAsync(request.Page, request.PageSize, totalCount);
以上代码的主要目的是为了在结果中输出IOList ,IOList是一个List<RobotReportRbkreportDIorDO>,主表与这个表RobotReportRbkreportDIorDO的关系是1对多,我想直接在多条主表数据的每条数据中直接输出IOList,是否有其他方案可以解决,以上是我处理方法,但是会报错。.GroupBy(a => a.uuid)之后就报错了
热忱回答(7)
-
fate sta VIP0
1个月前分组不是这么用的
不是groupby中的列要加 聚合函数
0 回复 -
格物致知 VIP0
1个月前关于这块的文档说明在哪里可以看,我没找到关于这块的详细说明
0 回复 -
格物致知 VIP0
1个月前@fate sta:关于这块的文档说明在哪里可以看,我没找到关于这块的详细说明
0 回复 -
棉花糖 VIP0
1个月前0 回复 -
fate sta VIP0
1个月前@格物致知:这个是SQL的知识。。 select name from table group by id 这样就会报错
0 回复 -
fate sta VIP0
1个月前select max(name) from table group by id 这样就不会报错
0 回复 -
格物致知 VIP0
1个月前@fate sta:sql知识我知道,我的意思是对应的sqlsugar语法怎么写,select里面加聚合函数要加什么聚合函数,我实际需求只要显示对应的字段(其实1对1就一个值,因为只有一个1对多的需要聚合输出List),所以能不能帮忙看看用sqlsugar要怎么写,我文档里面没有找到联表加分组比较详细的说明。
0 回复