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

原表:

在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. 记一次redis集群搭建过程

    在搭建前,我们先用vmware创建3台虚拟机,并确保它们相互之间能够ping通. 1. redis源码安装 1.1 编译安装 apt install gcc make wget http://down ...

  2. kafka 常见命令以及增加topic的分区数

    基础命令 1.创建topic kafka-topics.sh --bootstrap-server ${kafkaAddress} --create --topic ${topicName} --pa ...

  3. vue2中底层响应式数据实现

    <input type="text" id="textInput" />输入:<span id="textSpan"> ...

  4. VP做弹出窗体:查询数据并回传

    1.父页面VP定义传递数据:VP属性:DataContractMembrs 传递参数1:销售订单,用于给到子页面 传递参数2:表格行,用户子页面回传回来父页面(定义为None,通过代码来写进父页面表格 ...

  5. 达芬奇18.1.2安装包下载+软件详细破解安装教程(Win&Mac)

    DaVinci Resolve v18.1.2是一款在同一个软件工具中,将剪辑.调色.视觉特效.动态图形和音频后期制作融于一身的解决方案!它采用美观新颖的界面设计,易学易用,能让新手用户快速上手操作, ...

  6. js处理url插件库query-string

    http://www.wjhsh.net/smile-fanyin-p-15016684.html

  7. YOLOV4网络

    Yolov4网络代码 from collections import OrderedDict import torch import torch.nn as nn from Darknet_53 im ...

  8. 浅谈Redis与分布式锁

    为什么需要分布式锁 Redis如何实现分布式锁 如何避免死锁? 锁被别人释放怎么办? 锁过期时间不好评估怎么办? Redlock 真的安全吗 为什么要在多个实例上加锁? 为什么大多数实例加锁成功,才算 ...

  9. uniapp 样式记录

    flex https://uniapp.dcloud.io/nvue-css display: flex;/* 容器布局 */ flex:1; overflow: scroll;/* 容器内滚动条 * ...

  10. Rocky linux command-1

    在Linux下一切皆文件 everything is file,包括目录也是文件的一种而这些文件被分为七种类型: • -:普通文件 • d: 目录文件 • b: 块设备 • c: 字符设备 • l:  ...