Pivot for redshift database

后端 未结 4 586
自闭症患者
自闭症患者 2021-01-04 02:02

I know this question has been asked before but any of the answers were not able to help me to meet my desired requirements. So asking the question in new thread

In r

4条回答
  •  遥遥无期
    2021-01-04 02:46

    @user3600910 is right with the approach however 'END' is required else '500310' invalid operation would occur.

    select id,
           name,
           sum(case when Category='Coffees' then count END) as Cofees,       
           sum(case when Category='Milkshakes' then count END) as Milkshakes,
           sum(case when Category='Beer' then count END) as Beer,
           sum(case when Category='Snacks' then count END) as Snacks
    from my_table
    group by 1,2
    

提交回复
热议问题