You can do this using unpivot
. However, the simplest method if the data is not too big is just to use union all
:
select station, "from(m)", "to(m)", "ob.1" as Materials, Percent1 as Percent
from table t
union all
select station, "from(m)", "to(m)", "ob.2" as Materials, Percent2 as Percent
from table t
union all
select station, "from(m)", "to(m)", "ob.3" as Materials, Percent3 as Percent
from table t;
Note that you have three columns called Percent
. That is not allowed in a SQL table, so I assume they have different names.
Another method using cross join
or unpivot
would generally have better performance if your table is really larger.