如何从 1 行中 table 的 2 个不同行获取值以保存在 mssql 中的临时 table

How to get value from 2 different row of table in 1 row to save in temp table in mssql

我有一个 aff_attributes table 有数据

att_id  aff_id   att_name   att_value
978    12        address1   123 agajanian drive
979    12        zip        97654
980    12        city       canyon country

所以我想将它存储在临时 table 中,有 1 行

affid     address1               zip   city
12        123 agajanian drive    97654   canyon country

尝试使用 PIVOT 之类的东西......

SELECT *
FROM (
      SELECT aff_id
            ,att_name
            ,att_value
      FROM aff_attributes
   ) t
 PIVOT (MAX(att_value)
        FOR att_name
        IN (address1, zip, City))p