【问题标题】:Sub Query with Aggregate Function in where clause not working in SOQL Salesforce带有聚合函数的子查询 where 子句在 SOQL Salesforce 中不起作用
【发布时间】:2018-06-29 19:12:21
【问题描述】:

我在 Salesforce 中编写了一个非常简单的 SOQL 查询,但它不起作用。

SELECT Id, UserId, TerritoryId, IsActive 
FROM UserTerritory 
WHERE UserId NOT IN (SELECT UserId 
                    FROM UserTerritory 
                    GROUP BY UserId  
                    HAVING COUNT(UserId) > 1)

上面的查询抛出以下异常:

  1. 在开发者控制台显示“Unknown error parsing query”
  2. 在 Workbench 中显示:

MALFORMED_QUERY: (SELECT UserId FROM UserTerritory GROUP BY UserId HAVING count(UserId) ^ 错误在 Row:1:Column:114 期待 右括号,找到'GROUP'

【问题讨论】:

    标签: salesforce soql


    【解决方案1】:

    这样的查询无论如何都没有意义。

    假设您已将原始 SOQL 简化如下:

    SELECT Id, UserId, TerritoryId, IsActive 
    FROM UserTerritory 
    WHERE UserId NOT IN (SELECT UserId FROM UserTerritory)
    

    Salesforce 不允许您这样做,并且将引发异常:

    The inner and outer selects should not be on the same object type
    

    如果需要更彻底的分析,则需要有关该主题的更多详细信息(最好是数据示例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多