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

原表:

在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. 2、Maven

  2. 【离线数仓环境搭建】安装linux及安装JDK

    创建新的虚拟机 配置网络 安装vim sudo yum install -y vim 修改免密 sudo vim /etc/sudoers (执行安装命令的时候,不再需要输入密码) 查看防火墙状态 s ...

  3. 配dns

    cat /etc/resolv.conf

  4. javascript获取浏览器窗口分辨率|浏览器全屏分辨率|屏幕分辨率

    浏览器窗口分辨率指显示网页的区域,在PC端由于浏览器窗口大小可调节,这个值是可变的.在手机等移动端浏览器窗口大小不可调节,宽度值是固定的,但竖屏和横屏切换会改变. 浏览器全屏分辨率是指浏览器启用全屏显 ...

  5. 浅谈组件二封-vue

    目录 组件二封不是换一种写法 组件二封应当具备哪些条件 我认为的二封应当有哪些作用 二封的好处 先来一个列表页demo来看看效果(Vue2) 本文仅仅针对vue系列做探讨, 项目倾向于大量增删改查的后 ...

  6. pytest设计项目结构

    api目录封装所有的接口 testcases目录写所有的测试用例.conftest全局登录前置操作 data目录测试数据 common或者utils目录.存放公共模块比如读取yml文件.连接数据库.所 ...

  7. Java基础__03.异常

    什么是异常? 异常是指程序运行中出现的各种例外情况,如文件找不到.网络连接失败.传参错误...异常发生在程序运行期间,它影响了正常的程序执行流程. 异常体系结构: 在java中,异常是被当作对象来处理 ...

  8. gson TypeAdapter 和FieldNamingStrategy,SerializedName实现属性名称的设置别名

    gson TypeAdapter 和FieldNamingStrategy,SerializedName实现属性名称的设置别名 package com.example.core.mydemo.Type ...

  9. Linux: Ensure X Window System is not installed

    参考 2.2.2 Ensure X Window System is not installed X window System是什么 The X Window System provides a G ...

  10. zabbix中文显示乱码解决

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