1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

[SQL] How to pivot multiple aggregation in Snowflake

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 3, 2021.

  1. Stack

    Stack Membro Participativo

    I have the table structure as below

    product_id Period Sales Profit
    x1 L13 $100 $10
    x1 L26 $200 $20
    x1 L52 $300 $30
    x2 L13 $500 $110
    x2 L26 $600 $120
    x2 L52 $700 $130

    I want to pivot the period column over and have the sales value and profit in those columns. I need a table like below.

    product_id SALES_L13 SALES_L26 SALES_L52 PROFIT_L13 PROFIT_L26 PROFIT_L52
    x1 $100 $200 $300 $10 $20 $30
    x2 $500 $600 $700 $110 $120 $130

    I am using the snowflake to write the queries. I tried using the pivot function of snowflake but there I can only specify one aggregation function.

    Can anyone help as how I can achieve this solution ?

    Any help is appreciated.

    Thanks

    Continue reading...

Compartilhe esta Página