mysql5.7 select字段与group by不一致报错

执行语句

select s.office_name, s.office_id officeId from tb_sign_file s where s.status='1' group by s.office_name;

错误信息

[42000][1055] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yxqdoctor202006.s.office_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

SQL会报错,因为5.7版本之后的MYSQL不在group by里的字段 跟在select会报错解决办法是,用函数 any_value(字段名)

修改的SQL

select s.office_name, any_value(s.office_id) officeId from tb_sign_file s where s.status='1' group by s.office_name;

 

你可能感兴趣的:(MySQL,mysql)