Newer Version Available

This content describes an older version of this product. View Latest

GROUPING(fieldName)

You can use the GROUPING(fieldName) function in SELECT, HAVING, and ORDER BY clauses.

Use the GROUPING(fieldName) function to determine whether a row is a subtotal or field when you use GROUP BY ROLLUP or GROUP BY CUBE in SOQL queries.

GROUPING(fieldName) returns 1 if the row is a subtotal for the field, and 0 otherwise.

1SELECT LeadSource, Rating,
2    GROUPING(LeadSource) grpLS, GROUPING(Rating) grpRating,
3    COUNT(Name) cnt
4FROM Lead
5GROUP BY ROLLUP(LeadSource, Rating)

For more details, see Identify Subtotals with GROUP BY.