1.说明
报错原因是查询语句中与分组字段不匹配,查询的必须作为全部的分组字段
2.暂时解决
执行如下sql可以暂时解决,重启后失效
set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
3.修改配置文件
修改mysql配置文件,mysqld:下面加
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
4.如果是阿里云数据库,修改参数
如果是阿里云数据库出现SELECT list is not in GROUP BY clause and contains nonaggregated column解决
修改这个参数sql_mode,把only开头的设置删除
5.修改sql
大致思路是先查询出每天最新的数据,然后分组,后面通过连接查询
SELECT t1.id as id,t1.data as data,t1.time_type as timeType ,DATE_FORMAT(t1.gmt_create, '%Y-%m-%d' ) as date FROM ra_us_record AS t1 RIGHT JOIN ( SELECT MAX(gmt_create) AS max_date FROM ra_us_record WHERE user_id = 88898 and DATE_FORMAT( gmt_create, '%Y-%m' ) = '2023-04' GROUP BY DATE_FORMAT( gmt_create, '%Y-%m-%d' ) ) AS t2 ON t1.gmt_create = t2.max_date ORDER BY t1.gmt_create desc
还没有评论,来说两句吧...