问题描述
我有一个表,其中包含字段名和字段值之类的字段。我正在尝试将此表转换为另一种格式。
例如,我在下表中包含字段和值:
-----------------------------
| Fieldname | Fieldvalue |
-----------------------------
| Matnr | 001 |
| Werks | 1000 |
| Statu | 01 |
-----------------------------
我想用以下列名和值创建一个内部表:
-------------------------------
| Matnr | Werks | Statu |
-------------------------------
001 1000 01
我该怎么做?
解决方法
您可以使用条件聚合:
select max(case when fieldname = 'Matnr' then fieldvalue end) as matnr,max(case when fieldname = 'Werks' then fieldvalue end) as Werks,max(case when fieldname = 'Statu' then fieldvalue end) as Statu
from t;