سؤال

Is there something equivalent to the excel countif function (http://www.techonthenet.com/excel/formulas/countif.php) in SOQL ?

This is especially important in group by queries.

In oracle I would use the case function together with the case function

sum(
    case
         when (condition is true) 
          then 1 else 0 
  end
) 

How do i perform the same in salesforce SOQL?

Thanks,

David

هل كانت مفيدة؟

المحلول

This is one place where SOQL is not the equal of SQL. There is no CASE statement in SOQL, and there's really no way to accomplish a pivot here. We recently solved a similar problem by querying all rows and then accumulating the pivoted values using Apex, and then exposing that as an Apex web service so we could call the query on demand.

نصائح أخرى

When using group by you could use HAVING clause to filter the aggregate function by criteria.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top