Skip to main content
Skip to main content
Edit this page

groupArrayDistinct

Description

The groupArrayDistinct combinator can be applied to the groupArray aggregate function to create an array of distinct argument values.

Example usage

For this example we'll make use of the hits dataset available in our SQL playground.

Imagine you want to find out, for each distinct landing page domain (URLDomain) on your website, what are all the unique User Agent OS codes (OS) recorded for visitors landing on that domain. This could help you understand the variety of operating systems interacting with different parts of your site.

SELECT
    URLDomain,
    groupArrayDistinct(OS) AS distinct_os_codes
FROM metrica.hits_v1
WHERE URLDomain != '' -- Consider only hits with a recorded domain
GROUP BY URLDomain
ORDER BY URLDomain ASC
LIMIT 20;

See also