1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Confusion Encountered When Using arrayJoin Function and GROUP BY Clause in ClickHouse

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 17, 2024 às 10:05.

  1. Stack

    Stack Membro Participativo

    the first sql

    SELECT rtx
    , arrayJoin(['Istanbul', 'Berlin', 'Bobruisk']) AS city
    FROM (
    SELECT 'hi' as rtx
    )
    where city = 'Istanbul'
    group by rtx, city;


    the result is

    rtx city
    hi Istanbul

    the next sql

    SELECT rtx
    , arrayJoin(['Istanbul', 'Berlin', 'Bobruisk']) AS city
    FROM (
    SELECT 'hi' as rtx
    )
    where city = 'Istanbul'
    group by rtx;


    the result is

    | rtx | city |
    | -------- | -------- |
    | hi | Istanbul |
    | hi | Berlin |
    | hi | Bobruisk |


    I don't know why the result of second sql is so confusing. It's just like arrayJoin function is executed twice, before group by and after group by.

    when the column that arrayJoin func generates is not in the group by clause, what is the sql execution order

    Continue reading...

Compartilhe esta Página