mysq 报错, sql语句在数据库里运行正常, 在内网测试正常,打包放外网的时候就报下面错误

sql语句为:

select t1.day as day , any_value(IFNULL(t2.avgNum,0)) as avgNum, any_value(IFNULL(t2.maxNum,0)) as maxNum
            from ( SELECT date_add( date_sub('2021-03-01',interval 1 day), INTERVAL ( cast( help_topic_id AS signed ) + 1 ) day ) day  
            FROM mysql.help_topic
            WHERE help_topic_id <= DATEDIFF('2021-03-03',date_sub('2021-03-01',interval 1 day))) t1
            left JOIN
            (select ctime, any_value(sum(hourNum)) as avgNum, any_value(MAX(hourNum)) as maxNum from ( select any_value(DATE_FORMAT(create_time,'%Y-%m-%d')) as ctime, any_value(DATE_FORMAT(create_time,'%Y-%m-%d-%H')) as chour, count(*) as hourNum
            from game_log.player_login_log
            where server_id = 196 and DATE_FORMAT(create_time,'%Y-%m-%d') >= '2021-03-03'
            and DATE_FORMAT(create_time,'%Y-%m-%d') <= '2021-03-03'  group by  chour) t group by ctime ) t2
            ON t1.day = t2.ctime  ORDER BY t1.day
          

message:
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'game_log.player_login_log.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
### The error may exist in com/manage/dao/mapper/IReportMapper.java (best guess)
### The error may involve com.manage.dao.mapper.IReportMapper.game2-Inline
### The error occurred while setting parameters
### SQL: select t1.day, IFNULL(t2.avgNum,0) avgNum, IFNULL(t2.maxNum,0) maxNum from   (  SELECT  date_add( date_sub(?,interval 1 day), INTERVAL ( cast( help_topic_id AS signed ) + 1 ) day ) day   FROM  mysql.help_topic   WHERE  help_topic_id < DATEDIFF(?,date_sub(?,interval 1 day))  ) t1   LEFT JOIN   (  select ctime, ROUND(sum(hourNum)/24) as avgNum, MAX(hourNum) as maxNum  from   (  select DATE_FORMAT(create_time,'%Y-%m-%d') ctime, DATE_FORMAT(create_time,'%Y-%m-%d-%H') chour, count(*) hourNum from game_log.player_login_log where server_id = ? and DATE_FORMAT(create_time,'%Y-%m-%d') >= ? and DATE_FORMAT(create_time,'%Y-%m-%d') <= ?  group by  chour  ) t group by ctime  ) t2 ON t1.day = t2.ctime ORDER BY t1.day
### Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'game_log.player_login_log.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'game_log.player_login_log.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

网上查出报错原因:

数据库设置了只读事务(保证了事务级别的读一致性),查询是一个事务的开始,但是在查询中有修改操作。

解决:

将运算部分查出,在代码里运算;

 

posted @ 2021-03-04 15:05  心态良  Views(184)  Comments(0Edit  收藏  举报