我想得到大于男女平均年龄的人

原表:

在gauss200下执行以下语句:

SELECT stname,age,gender,AVG(age) FROM att_test01 GROUP BY gender HAVING age > AVG(age);

报错:column att_test01.stname must appear in the group by clause or be used in an aggregate function

gauss200是基于开源的postgres-XC开发的分布式关系型数据库系统,这是postgres常见的聚合问题。

解决方法如下:

SELECT b.stname,b.gender,b.age,a.avg FROM (SELECT gender,AVG(age) AS avg FROM att_test01 GROUP BY gender) a LEFT JOIN att_test01 b ON a.gender = b.gender AND b.age > a.avg;

将聚合放到子查询当中,然后与原表进行联合查询。

执行结果:

postgresql--column must appear in the group by clause or be used in an aggregate function的更多相关文章

  1. 【理解】column must appear in the GROUP BY clause or be used in an aggregate function

    column "ms.xxx_time" must appear in the GROUP BY clause or be used in an aggregate functio ...

  2. must appear in the GROUP BY clause or be used in an aggregate function

    今天在分组统计的时候pgsql报错 must appear in the GROUP BY clause or be used in an aggregate function,在mysql里面是可以 ...

  3. [mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'loser.tank_admin.login_ip' which is not functionally dependent on columns in GROUP BY clause; this is

    执行SQL: SELECT login_name,login_ip,sex FROM tank_admin GROUP BY login_name ; 时抛出异常. Expression #2 of ...

  4. SELECT list is not in GROUP BY clause and contains nonaggregated column

    报错如下: Expression # of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘sss.m ...

  5. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    安装了mysql5.7.19后,执行语句中只要含有group by 就会报这个错 [Err] 1055 - Expression #1 of ORDER BY clause is not in GRO ...

  6. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

    安装了mysql5.7,用group by 查询时抛出如下异常: Expression # of SELECT list is not in GROUP BY clause and contains ...

  7. MYSQL---Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column '

    --数据库中插入数据或执行sql语句时一直报下面这个错误: Expression # of ORDER BY clause is not in GROUP BY clause and contains ...

  8. mysql问题解决SELECT list is not in GROUP BY clause and contains nonaggregated column

    今天在Ubuntu下的部署项目,发现一些好好的列表页面发生 :Expression # of SELECT list is not in GROUP BY clause and contains no ...

  9. 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...

  10. 解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat

    解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat ...

随机推荐

  1. GIT Authentication failed for错误问题处理

    1. Settings ==> Developer settings ==> Personal access tokens ==> Generate new token   生成新的 ...

  2. windows安装和重装系统后无法识别U盘

    安装系统的方法: 1. 方案一,用大白菜制写入pe系统,但必须先准备Windows安装包 方案二,把ISO格式的系统安装包直接写入到u盘,写入U盘的方法请百度 2.开机看到电脑的logo后,按f2(不 ...

  3. jmeter分布式配置及问题记录

    环境配置:   假设有2台电脑,主机(10.1.5.219),从机(10.1.5.212) 主机:jdk.jmeter.脚本.脚本所需的文件(需配置jdk和jmeter的环境变量) 从机:jdk.jm ...

  4. EXE项目和DLL项目远程调试、Props设置说明

    通用宏设置 exe项目根据平台.配置设置输出路径: dll项目根据平台.配置设置输出路径,dll文件.lib文件分别输出到自己的路径: 中间文件根据平台.配置.项目设置输出路径: 设置远程调试命令.远 ...

  5. <string> <cstring> <string.h>

    <string>是C++标准库头文件,包含了拟容器class std::string的声明(不过class string事实上只是basic_string<char>的type ...

  6. oracle 索引创建

    --查询表里的索引 select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.inde ...

  7. matlab数操作

    随循环填充(更新)矩阵 不断更新矩阵,填充矩阵,可用cat函数: C = cat(dim,A,B); 向量重复扩充矩阵 将相同的向量或矩阵进行重复扩充时,matlab有两种方法:(第二种方法的效率更高 ...

  8. zabbix中文显示乱码解决

    问题zabbix使用中文显示,"监测-->图形"查看资源使用情况时会有乱码 解决问题1.修改配置文件(文件位置:$zabbix_path/include/defines.in ...

  9. jquery获取单选按钮选中的值

    jQuery 取选中的radio的值方法 var val=$('input:radio[name="sex"]:checked').val(); 附三种方法都可以: $('inpu ...

  10. 没解决的问题-git连接失败

    [parallels@localhost ~]$ ssh-keygen -t rsa -C '1012144290@qq.com'Generating public/private rsa key p ...