SQL Server将行转换为列并打印表数据[重复]

Conver the Row into column

我正在尝试将以下数据转换为列值并打印数据。

数据库:SQL Server

评论
  • 小不点er
    小不点er 回复

    您可以使用条件聚合:

    select id,
           max(case when attb_name = 'Job name' then value end) as job_name,
           max(case when attb_name = 'Created date' then value end) as created_date,
           max(case when attb_name = 'Created by' then value end) as created_by,
           max(case when attb_name = 'Job type' then value end) as job_type
    from t
    group by id;