zoukankan      html  css  js  c++  java
  • 小问题

    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'
  • 相关阅读:
    廖雪峰Java6IO编程-2input和output-1inputStream
    安装spy-debugger查看前端日志
    廖雪峰Java6IO编程-1IO基础-1IO简介
    廖雪峰Java5集合-6Stack-1使用Stack
    廖雪峰Java5Java集合-5Queue-1使用Queue
    廖雪峰Java5集合-4Set-1使用Set
    20)升级登录标志
    19)加了验证码验证
    94)图片验证码
    18)添加引号转移函数,防止SQL注入
  • 原文地址:https://www.cnblogs.com/NCL--/p/11532077.html
Copyright © 2011-2022 走看看