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 | Value 3
Into the following structure....
ID | Division | Department | Class
1 | Value 1 | Value 2 | Value 3
2 | Value 1 | Value 2 | Value 3
The number of columns is fixed (it will always be division/department/class). The query is intended for Sybase... have been unable to figure out how to achieve this sort of pivoting yet. Any advice?
Introduction to SQL Server PIVOT operator You follow these steps to make a query a pivot table: First, select a base dataset for pivoting. Second, create a temporary result by using a derived table or common table expression (CTE) Third, apply the PIVOT operator.
Exasol does not support the PIVOT function, but this example shows how it can be expressed in Exasol anyway. Exasol does not support the UNPIVOT function, but this example shows how it can be expressed in Exasol anyway. Both, Oracle and Exasol, support analytic functions. See Analytic Functions for more details.
We do this by clicking on the Pivot tab in the SQL Spreads Designer and then specifying the column we want to pivot and the column which has the values in it. The data in Excel is now pivoted.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With