一、翻译一个段,英语不好,见谅
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a16.a.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Syntax:语法。violation:违法。Expression:表达式。 clause:从句。contains:包含。nonaggregated:非聚集。functionally:功能性。dependent:依赖。incompatible:不兼容
二、only_full_group_by:
1、这个规则要求:凡是在group by后面出现的字段,必须同时在select后面出现;凡是在select后面出现的、同时未在聚合函数中出现的字段,必须同时出现在group by后面”,检查sql是否符合上述法则。
2、order by后面的列必须是在select后面存在的
3、select、having或order by后面存在的非聚合列必须全部在group by中存在
https://zhuanlan.zhihu.com/p/103283746
三、聚合函数(组合函数):聚合函数aggregation function又称为组函数。 默认情况下 聚合函数会对当前所在表当做一个组进行统计。https://www.cnblogs.com/xuchuankun/p/9483765.html
四、GROUP BY 语句:GROUP BY 语句用于结合聚合函数,根据一个或多个列对结果集进行分组。
五、group by详解:https://blog.csdn.net/jerrytomcat/article/details/82351605
https://blog.csdn.net/s00229295/article/details/96041555
六、Having与Where的区别
where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,where条件中不能包含聚组函数,使用where条件过滤出特定的行。
having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件过滤出特定的组,也可以使用多个分组标准进行分组。
七、MYSQL中GROUP BY不包含所有的非聚合字段:https://blog.csdn.net/liufei198613/article/details/82979034
八、多表查询似乎没有遵循上面的规则:以下代码没有报错,是什么原因呢?
$map['a.user_id'] = $this->auth->id;
$map['b.type'] = 1;
$map['b.deletetime'] = null;
$map['b.endtime'] = ['>', time()];
$map['b.starttime'] = ['<', time()];
$field = 'a.id, a.plan_id, b.plan_name, b.times, b.hours, b.endtime, b.starttime,b.type,b.exam_id,c.exam_name, max(d.lasttime) as lasttime';
$plans = $this->model
->alias('a')
->where($map)
->field($field)
->join('__KAOSHI_PLAN__ b', 'a.plan_id = b.id')
->join('__KAOSHI_EXAMS__ c', 'b.exam_id = c.id')
->join('__KAOSHI_USER_EXAMS__ d', 'a.id = d.user_plan_id', 'left')
->group('a.id, b.id')
->select();