0

我正在使用 SalesForce Mobile SDK 开发移动应用程序,并且为了使功能正常工作,我正在构建 customer_id 和相应地址之间的映射。因此,为了进行映射,我修改了 SOQL 查询,以便在执行查询后取回 customer_id 值。

当找到地址时,此映射工作正常。但是当没有关联的地址时,我没有得到任何响应。因此,映射一个 customer_id 并在其中放入一个空地址,即使找不到地址,我也需要返回 customer_id。

为了更好地解释:以下查询不返回任何结果,因为没有找到地址:

SELECT Account_vod__c,Address_line_2_vod__c, City_vod__c, Name FROM Address_vod__c WHERE Account_vod__c = '001e000000qVp8WAAS'

但我想创建一个查询,如果没有找到记录,它将返回如下内容:

在此处输入图像描述

4

3 回答 3

0

你可以尝试使用合并

SELECT coalesce(Account_vod__c,001e000000qVp8WAAS),
Address_line_2_vod__c, City_vod__c, Name 
FROM Address_vod__c WHERE Account_vod__c = '001e000000qVp8WAAS'
于 2018-11-20T17:13:04.673 回答
0

这回答了基于初始 DBMS 标记的问题:

SELECT a.Account_vod__c, a1.Address_line_2_vod__c, a1.City_vod__c, a1.Name
FROM (SELECT '001e000000qVp8WAAS' AS Account_vod__c) a LEFT OUTER JOIN
     Address_vod__c a1
     ON a1.Account_vod__c = a.Account_vod__c;

如果你有多个Account_vod__cs 然后使用UNION ALL& do LEFT JOIN

SELECT a.Account_vod__c, a1.Address_line_2_vod__c, a1.City_vod__c, a1.Name
FROM (SELECT '001e000000qVp8WAAS' AS Account_vod__c
      UNION ALL
      . . .
     ) a LEFT OUTER JOIN
     Address_vod__c a1
     ON a1.Account_vod__c = a.Account_vod__c;
于 2018-11-20T17:16:08.477 回答
0

嵌套 SOQL 查询起到了作用:

SELECT Id, Name,(SELECT Id, Account_vod__c, Name, Address_line_2_vod__c, City_vod__c FROM Address_vod__r)FROM Account WHERE Id = '001e0000008Ch5nAAC' LIMIT 1
于 2018-11-21T19:15:05.450 回答