In the provided dataset, data is currently pivoted with the user_id column as the primary identifier. However, the desired outcome is to pivot the data with both user_id and lang as the primary identifiers.
To achieve this, the PIVOT function can be employed. The PIVOT function takes an aggregated value and groups it by one or more columns, creating a new column for each group. In this case, the org and position columns will be aggregated and grouped by lang.
The following SQL query demonstrates how to pivot the data using multiple columns:
SELECT * FROM source PIVOT ( MIN(org) AS org, MIN(position) AS position FOR lang IN('EN' AS en, 'FI' AS fi, 'SV' AS sv) );
The PIVOT clause performs the pivoting operation:
The result of the query is a pivoted dataset with the following columns:
The above is the detailed content of How to Pivot Data Using Multiple Columns (user_id and lang) in SQL?. For more information, please follow other related articles on the PHP Chinese website!