暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

SUNDB group SQL报错解决

原创 科蓝SUNDB编辑部 2022-11-04
573

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

最后修改时间:2023-07-17 14:50:44
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论