Reputation: 15
Which is the similar command for unpivot in Firebird? TKS in advance...
My Table
Id | Name | Land | Water
-----|----------|--------|---------
1 | John | 300m | 100m
-----|----------|--------|---------
2 | Mark | 100m | 0m
-----------------------------------
Desired Result
Id | Name | Category | Surface
-----|--------|------------|--------
1 | John | Land | 300m
-----|--------|------------|--------
1 | John | Water | 100m
-----|--------|------------|--------
2 | Mark | Land | 100m
-----|--------|------------|--------
2 | Mark | Water | 0m
Upvotes: 1
Views: 1243
Reputation: 1269923
You can use union all
:
select id, col1 as col
from t
union all
select id, col2 as col
from t;
Something like this should work for most purposes.
EDIT:
For your particular data:
select id, name, 'Land' as category, land as surface
from mytable
union all
select id, name, 'Water' as category, water as surface
from mytable;
Upvotes: 3