首页 > 解决方案 > 收到错误错误:在 WHERE 位置中不允许使用聚合函数:98

问题描述

我试图找到我这样尝试customer过的minimum价值

select info->'customer'
from orders
where cast(info->'items'->>'qty' as INTEGER) =
      (select min(cast(info->'items'->>'qty' as INTEGER)))

这是我的代码

http://sqlfiddle.com/#!17/79606/17

出现错误 :WHERE Position: 98 中不允许使用聚合函数

预期答案“乔什·威廉”

标签: sqlpostgresqlpostgresql-9.1postgresql-9.4

解决方案


您的子查询缺少一个FROM子句。尝试:

select info->'customer'
from orders
where cast(info->'items'->>'qty' as INTEGER) =
      (select min(cast(info->'items'->>'qty' as INTEGER))
              from orders)

推荐阅读