【问题标题】:getting error ERROR: aggregate functions are not allowed in WHERE Position: 98收到错误错误:在 WHERE 位置中不允许使用聚合函数:98
【发布时间】:2019-02-21 21:23:00
【问题描述】:

我正在尝试查找minimum 值中的customer,我这样尝试过

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 中不允许使用聚合函数

预期的答案 “乔什·威廉”

【问题讨论】:

    标签: sql postgresql postgresql-9.1 postgresql-9.4


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 2017-06-16
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多