对于Firebird中的unpivot来说,这是类似的命令吗? TKS事先......
我的表
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
答案 0 :(得分:3)
您可以使用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;