📜  在 sql server 中将行转换为列 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:25.155000             🧑  作者: Mango

代码示例1
-- convert rows to columns in sql server (PIVOT)
SELECT Firstname, Amount, PostalCode
FROM (
         SELECT value, columnname
         FROM yourtable
     ) d
PIVOT (
    max(value)
    FOR columnname IN (Firstname, Amount, PostalCode)
) piv;