小问题

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'platform_test.p.positional' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决办法:

MySQL 5.7.5后only_full_group_by成为sql_mode的默认选项之一,这可能导致一些sql语句失效。

解决方法
把group by字段group_id设成primary key 或者 unique NOT NULL。这个方法在实际操作中没什么意义。

使用函数any_value把报错的字段name包含起来。如,select any_value(name), group_id from game group by group_id。

在配置文件my.cnf中关闭sql_mode=ONLY_FULL_GROUP_BY.。msqyl的默认配置是sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION。可以把ONLY_FULL_GROUP_BY去掉,也可以去掉所有选项设置成sql_mode=,如果你确信其他选项不会造成影响的话。

 eg:

  

SELECT
    su.user_id,
    su.user_no,
    su.create_user,
    su.create_time,
    su.update_user,
    su.update_time,
    i.NAME,
    i.sex,
    i.contact,
    a.start_time,
    a.education,
    b.positional,
    b.obtain_time,
    i.dept_id
FROM
    user_info i
    LEFT JOIN sys_user su ON su.user_id = i.user_id
    LEFT JOIN (
SELECT
    any_value(e.education) education,
    MAX( e.start_time ) start_time,
    any_value(e.id) id,
    e.user_id
FROM
    user_education e
GROUP BY
    e.user_id
ORDER BY
    start_time DESC
    ) a ON a.user_id = i.user_id
    LEFT JOIN (
SELECT
    any_value(p.positional) positional,
    MAX( p.obtain_time ) obtain_time,
    any_value(p.id) id,
    p.user_id
FROM
    user_positional p
GROUP BY
    p.user_id
ORDER BY
    obtain_time DESC
    ) b ON b.user_id = i.user_id
WHERE
    i.user_id != '1'

 

posted @ 2019-09-17 10:30  *眉间缘*  阅读(128)  评论(2编辑  收藏  举报