Pivoting in Sybase SQL Query?

后端 未结 2 994
执念已碎
执念已碎 2021-01-13 07:56

I am looking for a way to pivot the following results...

ID | Group_Level | Group_Values
1  | Division    | Value 1 
2  | Department  | Value 2
3  | Class            


        
2条回答
  •  执笔经年
    2021-01-13 08:04

    The classic way to pivot to a fixed number of columns is like this:

    select id,
    max (case when group_level = 'Division' then Group_Values else null end) Division,
    max (case when group_level = 'Department' then Group_Values else null end) Department,
    max (case when group_level = 'Class' then Group_Values else null end) Class
    from
    YourTable
    group by id
    

提交回复
热议问题