Converting multiple rows to columns with specified heading

前端 未结 2 1009
南旧
南旧 2021-01-04 23:51

I have a table that holds details of activities carried out by individuals - contents of this table is similar to the following:

| Person    | Category  | Activit         


        
2条回答
  •  星月不相逢
    2021-01-05 00:15

    this is a simple example

     SELECT 
           Person,  
           MAX(CASE Category WHEN 'X' THEN Activity ELSE 0 END) AS 'X'
           MAX(CASE Category WHEN 'Y' THEN Activity ELSE 0 END) AS 'Y'
           MAX(CASE Category WHEN 'Z' THEN Activity ELSE 0 END) AS 'Z' 
        FROM mytable
        GROUP BY Person
    

提交回复
热议问题