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 ...
随机推荐
- css 卡片hover效果
.card { height: 430px; width: 100%; background:#ffffff; border:1px solid #eaeefb; border-radius:5px; ...
- 日志服务化&可视化&统计化
概述: ELK是Elasticsearch(简称es).Logstash.Kibana的简称,这三者是核心套件,但并非全部. Filebeat 日志采集工具 Logstash数据处理引擎 ela ...
- wtform的用法
1.登录用法from flask import Flask, render_template, request, redirectfrom wtforms import Form,validators ...
- Spring Web MVC注解
@RequestMapping @RequestMapping注解的主要用途是将Web请求与请求处理类中的方法进行映射. Spring MVC和Spring WebFlux都通过RquestM ...
- AndroidStudio中的读取本地Gradle设置,gradle-wrapper.properties内容解释
gradle-wrapper.properties文件长成下面这个样子 distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distsd ...
- 【RUNOOB】C语言学习之指针
资料来源: (1) runoob; (2) C语言程序设计; 注1:Runoob中对于指针的讲述比较清晰简单,摘录出来(后续补充指针与结构体,指针与函数参数); 1.指针与变量的内存位置 (1) 每个 ...
- zookeeper(1)-集群的搭建
集群搭建 1. 下载二进制文件 $ wget --no-check-certificate https://mirrors.ustc.edu.cn/apache/zookeeper/zookeeper ...
- 【NPDP专项练习】第六章 市场研究
第六章 市场研究 1.VOC也叫客户心声,指的是. A 选择一个单一的投资组合项目,并保证所有项目都在策略内 B 利用迭代在专家组中形成共识的决策 C 通过人工"商店"引导潜在客户 ...
- Xamarin.Android 踩坑记
将数据发送给微信 var dbFile = Path.Combine(DBSetting.GetSetting().DBDirectory, $"{BLL.SelectProject.DBN ...
- ssh 免密访问
首先配置三台机器的hosts文件 填写需要配置的三台主机ip,然后命名,这里我写的时 t1 t2 t3 三台机器上都要配置hosts文件,要配置一样. 三台机器改完后保存退出 ping一下刚才配置的三 ...