为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:8
【操作系统】:win10
【CPU】:
【问题描述】*:使用mybatis-plus的mapper查询时报错
代码如下:List<String>appIdList=appMapper.selectList(Wrappers.<APP>lambdaQuery().eq(APP::getStatus,0).gruopBy(APP::getId)).stream().map(APP::getId).collect(Collectors.toList());
执行语句:select id,status,user_name from app where status=0 group by id
报错:不是gruop by 表达式
group by使用不标准,id,status,user_name都要跟在group by后面。
通用关系型数据库标准语法中,SELECT子句中的列名必须为分组列或列函数,列函数对于GROUP BY子句定义的每个组各返回一个结果。对该语句id,status,user_name字段均为分组列必须包含在GROUP BY中,如果不需要对status,user_name字段进行分组,需要在select中去掉该字段,如果又需要查询出project_name字段的值,可以考虑使用子查询的方式。
之前使用的是mysql数据库吗,可以尝试以下方式:
1、修改语句select id,status,user_name from app where status=0 group by id,status,user_name;
2、修改为mysql兼容模式(需重启数据库),修改dm.ini参数COMPATIBLE_MODE=4
3、修改参数sp_set_para_value(1,'GROUP_OPT_FLAG',53);非mysql兼容模式下支持查询项不是group by表达式,不需要重启