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

原表:

在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. 整合Junit5

    1.引入依赖 <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-j ...

  2. argocd

    argocd Argo CD - Declarative GitOps CD for Kubernetes (argo-cd.readthedocs.io) What Is Argo CD Argo ...

  3. uml类图中的+,-,#符号的含义

    描述类的属性的可见性: UML中,可见性分为4级 1.public 公用的 :用+ 前缀表示 ,该属性对所有类可见 2.protected 受保护的:用 # 前缀表示,对该类的子孙可见 3.priva ...

  4. IaaS--云虚拟机(二)(何恺铎《深入浅出云计算》笔记整理)

    [如何挑选合适的虚拟机型号] 1.根据类型.云厂商会提供均衡型.计算密集型.内存优化型.图形计算型等常见的虚拟机类型.这些类型对应着硬件资源的某种合理配比或针对性强化,方便你在面向不同场景时,选择最合 ...

  5. 2022-11-19学习内容-Server端代码编写-Client端代码编写

    1.Server端代码编写 1.1UserDBHelper.java package com.example.chapter07_server.database; import android.con ...

  6. mysql高级函数FIND_IN_SET,ENUM和SET,LOCATE,ELT,FIELD,INTERVAL,COUNT,CAST,NULLIF,ISNULL,IFNULL,IF,CONVERT,COALESCE

    mysql高级函数FIND_IN_SET,ENUM和SET,LOCATE,ELT,FIELD,INTERVAL,COUNT,CAST,NULLIF,ISNULL,IFNULL,IF,CONVERT,C ...

  7. Unity Profiler真机调试

    1.在BuildSetting面板中勾选DevelopmentBuild 2. .cmd命令: adb forward tcp:34999 localabstract:com.CompanyName. ...

  8. [Oracle19C 数据库管理] 管理PDB

    更改PDB的打开模式 RESTRICT模式 维护时使用,可以让只有RESTRICT权限的用户才能连接到数据库,其他用户无法连接. ALTER PLUGGABLE DATABASE 数据库名 CLOSE ...

  9. Android组件化开发-----页面路由(ARouter)

    平时开发中,我们经常用到页面跳转功能.之前我一直使用Intent过跳转 Intent intent = new Intent(A.this, B.class); intent.putExtra(&qu ...

  10. 蓝桥杯训练赛二-2021 问题 G: 坐标排序

    题目描述 请将坐标x,y,z依照以下规则排序: x为第一关键字,当x相同时,依照y(第二关键字)大小来排序,当y相同时,依照z大小来排序(第三关键字) 给出了若干坐标,和一个数k,请输出按关键字排序第 ...