0

AggregateResult[] groupedResultCall = [ SELECT Account_vod__c, count(Id) 
                                        FROM Call2_vod__c 
                                        WHERE Call_Date_vod__c >= :QuarterStartDate
                                          AND Call_Date_vod__c <= :QuarterEndDate 
                                          AND Account_Type__c =: accStaticRec.Account_Type__c 
                                          AND Territory_vod__c =: accStaticRec.Territory__c 
                                          AND Status_vod__c = 'Submitted_vod' 
                                          AND (Call_Type_vod__c != 'Call Only' 
                                            OR Call_Type_vod__c != 'Event Only' 
                                            OR Call_Type_vod__c != 'Event Detail')
                                          AND Account_vod__c IN :accIdSet                                                           
                                          AND Activity_Type__c <> 'Staff'
                                        GROUP BY Account_vod__c ];

 AggregateResult[] groupedResultCall = [SELECT Account_vod__c, count(Id) 
                                        FROM Call2_vod__c 
                                        WHERE Call_Date_vod__c >= :QuarterStartDate 
                                          AND Call_Date_vod__c <= :QuarterEndDate 
                                          AND Account_Type__c =:accStaticRec.Account_Type__c 
                                          AND Territory_vod__c = :accStaticRec.Territory__c 
                                          AND Status_vod__c = 'Submitted_vod' 
                                          AND (Call_Type_vod__c != 'Call Only' 
                                            AND Call_Type_vod__c != 'Event Only' 
                                            AND Call_Type_vod__c != 'Event Detail')
                                          AND Account_vod__c IN :accIdSet  
                                          AND Activity_Type__c <> 'Staff'
                                        GROUP BY Account_vod__c ];

哪个查询是正确的。请纠正我

4

2 回答 2

1

第2个是正确的。

AND (Call_Type_vod__c != 'Call Only' 
AND Call_Type_vod__c != 'Event Only' 
AND Call_Type_vod__c != 'Event Detail')

我想你想检索那些 'Call_Type_vod__c' 值不是这些值的行 ('Call Only', 'Event Only', 'Event Detail') 。所以第二个会起作用。

第一个查询将返回所有行

AND (Call_Type_vod__c != 'Call Only' 
OR Call_Type_vod__c != 'Event Only' 
OR Call_Type_vod__c != 'Event Detail')
于 2013-08-20T14:31:57.977 回答
0

查询之间的唯一区别在于嵌套 AND 条件

AND (Call_Type_vod__c != 'Call Only' 
  OR Call_Type_vod__c != 'Event Only' 
  OR Call_Type_vod__c != 'Event Detail')

VS

AND (Call_Type_vod__c != 'Call Only' 
  AND Call_Type_vod__c != 'Event Only' 
  AND Call_Type_vod__c != 'Event Detail')

它完全取决于您的数据模型和您对此查询结果的期望。

于 2013-08-20T03:34:00.790 回答