小問題

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

解決辦法:sql

MySQL 5.7.5後only_full_group_by成爲sql_mode的默認選項之一,這可能致使一些sql語句失效。函數

解決方法
把group by字段group_id設成primary key 或者 unique NOT NULL。這個方法在實際操做中沒什麼意義。this

使用函數any_value把報錯的字段name包含起來。如,select any_value(name), group_id from game group by group_id。spa

在配置文件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=,若是你確信其餘選項不會形成影響的話。code

 eg:orm

  

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'
相關文章
相關標籤/搜索