postgresql--column must appear in the group by clause or be used in an aggregate function
我想得到大于男女平均年龄的人
原表:

在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的更多相关文章
- 【理解】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 ...
- 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里面是可以 ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
- 解决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 ...
随机推荐
- 小白之Python-基础中的基础03
序列,目前看来很基础,东西比较多,难度开始加大...加油吧,骚年 Python之序列 1.数据结构:序列.容器(序列:索引.映射:键).集合2.列表.元组.字符串.Unicode字符串.buffer对 ...
- 为开源项目贡献代码-pycharm使用git-登录注册功能分析-判断手机号存在接口-多种方式登录接口-腾讯云短信申请
目录 为开源项目贡献代码-pycharm使用git-登录注册功能分析-判断手机号存在接口-多种方式登录接口-腾讯云短信申请 git内容大回顾 今日内容概要 今日内容详细 1 为开源项目贡献代码 2 p ...
- (原创)odoo14下qweb模板的前端与后端语法区别
1.后端(qweb打包) 后端使用t-inherit 指定继承的模板,使用t-inherit-mode 指定继承的模式,使用xpath定位标记,使用position指定扩展位置. 2.前端 前端仍旧使 ...
- 排查前端接受后端的map产生的字段错误
报错内容 [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingExce ...
- weboack5webpack5用url-loader(file-loader)处理字体
file-loader(url-loader)可以用解析打包字体. webpack配置loader \\ webpack.config.js const webpack = require(" ...
- debian11用iso制作本地apt源
摘抄记录,原文链接: https://blog.csdn.net/leejearl/article/details/122708953?spm=1001.2101.3001.6650.1&ut ...
- vscode远程连接服务器出现Bad owner or permissions on .ssh/config
vscode远程连接服务器出现Bad owner or permissions on C:\\Users\USER\.ssh/config 过程试图写入的管道不存在, 原因是vscode的remoto ...
- python读取xml格式数据
读取节点文本值和,属性值 # -*- coding: UTF-8 -*- from xml.dom import minidom dom=minidom.parse('F:\\python_proje ...
- 通过Jenkins在远程服务器上执行shell脚本
1.Jenkins安装Publish over SSH插件 下载安装Publish over SSH插件 2.配置服务器相关信息 要先在jenkins所在的机器上生成秘钥.生成方式为: ssh-key ...
- rsyslog由于RateLimit丢失日志的处理
问题 问题的发现:在我们的docker应用中,配置了rsyslog作为日志输出:当应用产生的日志在某段时间内量比较大时,就发现会丢日志. 原因 问题的原因:日志的输出路径,应用程序把日志输出到syst ...