1. 问题描述
报错信息:ERR-42000(16161): not a single-group group function
数据库版本:Release 5.0 22.1.0 revision(28cd72e)
错误代码:ERR-42000(16161): not a single-group group function
2. 复现环境
create table t_group(id int,name char,context long varchar,time date);
insert into t_group values(1,‘a’,‘abcdef’,‘2022-10-28’);
insert into t_group values(2,‘b’,‘bcdef’,‘2022-10-28’);
insert into t_group values(3,‘c’,‘cdef’,‘2022-10-28’);
执行如下语句,直接报错:
select id from t_group group by time;
ERR-42000(16161): not a single-group group function :
3. 问题原因
是因为group by的字段在表里有重复值,它不知道显示那条记录导致。
4. 解决方案
select min(id) from t_group group by time;
在解决此问题的时候,碰到一个新的问题:错误代码如下:
ERR-42000(16246): illegal use of LONG VARCHAR data type :
错误的是提示很明显,是因为long varchar数据类型的问题导致,不能进行min max……之类的操作。
复现语句:
select min(id),min(CONTEXT) from t_group group by time;
ERR-42000(16246): illegal use of LONG VARCHAR data type
解决方式:
select tt.id,tt.name,tt.context,tt.time from t_group tt join ( select min(id) as mid from t_group group by time ) t on t.mid = tt.id




