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

原表:

在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. C# RGB转Brush

    C#中自定义一个Brush,使用Color赋RGB值给Brush: dataGrid2.HorizontalGridLinesBrush = new SolidColorBrush(System.Wi ...

  2. eccodes 使用girb_filter工具

    参考自ECMWF网站https://confluence.ecmwf.int/display/OPTR/ecCodes%3A+GRIB+and+BUFR+data+decoding+and+encod ...

  3. k8s_使用k8s部署博客系统deployment(四)

    mysql deployment 前面的nfs  pv pvc secret configmap service等k8s对象已经创建好了,准备工作已经完成:现在可以开始准备deployment配置文件 ...

  4. Azkaban 4.0.0 系列(一)-- Solo-Server

    下载 链接 https://github.com/azkaban/azkaban/releases/4.0.0.tar.gz 解压 tar -xzvf 4.0.0.tar.gz -C 自定义目标目录 ...

  5. redis常用命令之Hash

    redis常用命令之Hash Hash常用命令 redis 可以理解为一个全局的大字典,key就是数据的唯一标识符.对应的key不同,value也不同.redis有5个基本的数据类型. 1 redis ...

  6. ASP.NET WebAPI 单元测试-UnitTest

    xUnit.Net

  7. dialog弹窗里生成二维码 (reading qppendChild)

    在dialog弹窗里生成二维码第一次点击时 dialogFormVisible.value=false,二维码生成时会找不到对象可以用nextTick()函数 将二维码生成代码放到nextTick() ...

  8. vue v-for 使用

    html <div> <el-button @click="addListItem" type="primary" style="p ...

  9. python利用xlwings写入一行或一列Excel数据

    注意点:这里的sheet参数默认是已经存在的sheet表,如不存在该sheet,则使用add方法新增即可,示例: wb = xw.Book(r"C:\Users\Desktop\result ...

  10. 第八章:diff

    1.git  diff命令的格式 1]可以使用git  diff命令的来源,(任意树对象.工作目录.索引) 2]git  diff命令进行树比较时,可以通过(提交名.分支名.标签名) 3]git  d ...