The COUNTDISTINCTMEMBERS
function counts the number of elements in a set that has the union of all its values.
COUNTDISTINCTMEMBERS
is functionally equivalent to this statement:
CARDINALITY(SET_UNIONS(multi-assign-attribute))
That is, COUNTDISTINCTMEMBERS
first constructs a set that is the union of all the values from a multi-assign attribute and then returns the number of elements in that set.
COUNTDISTINCTMEMBERS syntax
COUNTDISTINCTMEMBERS
function is:
COUNTDISTINCTMEMBERS(<multi-assign-attribute>)
where multi-assign-attribute is a multi-assign attribute.COUNTDISTINCTMEMBERS example
Body WineID -------------------------- { Silky, Tannins } 3 { Robust, Tannins } 4 { Silky, Tannins } 5 { Robust } 6 { Robust } 8 { Silky, Tannins } 9 { Silky, Tannins } 12 { Silky, Tannins } 16 { Silky, Tannins } 18 --------------------------
RETURN Result AS SELECT COUNTDISTINCTMEMBERS(Body) AS Total FROM WineState WHERE WineType = 'Red' GROUP BY WineType
Total=3, WineType=Red
Thus, there are three sets of distinct values for the Body attribute, when grouped by the WineType attribute.