在 Firebird 中将列转换为行(unpivot 命令)

Convert columns to rows in Firebird (unpivot command)

Firebird 中与 unpivot 类似的命令是什么?提前TKS...

我的Table

 Id  |  Name    |  Land  |   Water
-----|----------|--------|---------
 1   |  John    |  300m  |    100m
-----|----------|--------|---------
 2   |  Mark    |  100m  |     0m
-----------------------------------

期望的结果

 Id   |  Name  |   Category | Surface
 -----|--------|------------|--------
 1    |  John  |    Land    |   300m
 -----|--------|------------|--------
 1    |  John  |    Water   |   100m
 -----|--------|------------|--------
 2    |  Mark  |    Land    |   100m
 -----|--------|------------|--------
 2    |  Mark  |    Water   |    0m

您可以使用 union all:

select id, col1 as col
from t
union all
select id, col2 as col
from t;

像这样的东西应该适用于大多数用途。

编辑:

对于您的特定数据:

select id, name, 'Land' as category, land as surface
from mytable
union all
select id, name, 'Water' as category, water as surface
from mytable;