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

原表:

在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. ubuntu 20.04 ibus添加五笔输入法

    ubuntu 20.04 ibus添加五笔输入法:虽然现在五笔输入法已经没有什么新人使用,如果还有一两个人,找不到系统自带的极点五笔输入,可以按如下方式操作:以前是用ibus-setup,点添加,现在 ...

  2. Docker CLI docker buildx bake 常用命令

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化.Docker是内核 ...

  3. webpack5用url-loader(file-loader)处理图片和img-loader压缩图片

    webpack-cli 4.0的版本和 webpack-dev-server 3.11.0的版本不兼容,只能用webpack@5.0 + webpack-cli@3.3.12 + webpack-de ...

  4. 代码格式 linux

    indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl test.c

  5. 读后笔记 -- Java核心技术(第11版 卷 II) Chapter5 数据库编程

    5.1 JDBC API 1. JDBC (Java Database Connectivity) is an API for interacting with a database in Java. ...

  6. Mybatis插件-分批次插入数据

    背景 有时候使用insert into xxx values (),()语句插入大量数据时,会使得SQL语句超长,为了解决这个问题,在Mybatis中编写一个分批次插入的插件. 实现 package ...

  7. corkscrew在ssh中发生错误

    使用绝对路径 ProxyCommand="corkscrew 127.0.0.1 12345 jump.123.com 2020" abc@efg.com 改为 ProxyComm ...

  8. mi

    小米耳机页面 <style> * { margin: 0; padding: 0; } body { width: 1226px; background-color: #f5f5f5; m ...

  9. (一)REDIS之常见数据结构及操作

    (一)基本数据结构 1.1 String结构: String底层结构是动态字符串,可修改指定位置数据,通过预分配冗余空间减少内存的频繁分配,实际分配的空间capacity一般要高于实际字符串长度len ...

  10. 87、linux root 密码忘记了

    子账户登录,然后重置即可