道歉,如果这不是主题,但我相信这里有人可以给我一个答案。我有一个MySQL查询,在我的主机上运行正常。我刚刚在家用计算机上安装了LAMP,当我在PHPadmin中测试此查询时,它失败并出现此错误:
#1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test_table.p.user_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
我在Apache 2上运行PHP 5.6。
这是我的工作查询
SELECT up.file,p.user_name,p.user_id, GROUP_CONCAT(c.collab_username)
FROM tbl_uploads up
LEFT JOIN tbl_users p ON up.user_id = p.user_id
LEFT JOIN tbl_collab c ON up.file = c.file
GROUP BY up.file ORDER BY up.date DESC
谁能告诉我这个错误意味着什么?
答案 0 :(得分:0)
启动mysql 5.7如果不在group by子句中,你可以(默认情况下)使用非聚合列,
因为这不会产生预定的结果,因为没有聚集的cols
或者以正确的方式配置mysql,设置正确的sql_mode或
一种简单的方法是为所有不在组中的col添加聚合函数,例如:
SELECT up.file, min(p.user_name) , min(p.user_id), GROUP_CONCAT(c.collab_username)
FROM tbl_uploads up
LEFT JOIN tbl_users p ON up.user_id = p.user_id
LEFT JOIN tbl_collab c ON up.file = c.file
GROUP BY up.file
ORDER BY up.date DESC