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

[SQL] BigQuery: Return First Value from Different Groups in a Group By

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

  1. Stack

    Stack Membro Participativo

    I am currently having a problem with a Standard SQL query. I have a list of emails where every email can have multiple functions. See the example below on how the table looks like.

    Email Function
    peter@gmail.com engineer
    peter@gmail.com specialist
    dave@gmail.com analyst
    dave@gmail.com tester
    dave@gmail.com manager
    michael@gmail.com intern


    What I want is a query that returns every email once with the first function it finds. So the above table should return the following:

    Email Function
    peter@gmail.com engineer
    dave@gmail.com analyst
    michael@gmail.com intern


    How do I do this?

    What I have right now is a simplified version of the query.

    SELECT Email, Function
    FROM database
    GROUP BY Email, Function


    The issue is here is that I have to put both Email and Function in the GROUP BY. If I only put Email in the Group By the query cannot run even though I only want the query to GROUP BY Email.

    Thanks!

    Continue reading...

Compartilhe esta Página