Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

groupArrayArray

Aggregates arrays into a larger array of those arrays. Combines the groupArray function with the Array combinator.

Alias: array_concat_agg

Example

We have data which captures user browsing sessions. Each session records the sequence of pages a specific user visited. We can use the groupArrayArray function to analyze the patterns of page visits for each user.

Setupsql
CREATE TABLE website_visits (
    user_id UInt32,
    session_id UInt32,
    page_visits Array(String)
) ENGINE = Memory;

INSERT INTO website_visits VALUES
(101, 1, ['homepage', 'products', 'checkout']),
(101, 2, ['search', 'product_details', 'contact']),
(102, 1, ['homepage', 'about_us']),
(101, 3, ['blog', 'homepage']),
(102, 2, ['products', 'product_details', 'add_to_cart', 'checkout']);
Querysql
SELECT
    user_id,
    groupArrayArray(page_visits) AS user_session_page_sequences
FROM website_visits
GROUP BY user_id;
Responsesql
Navigation