سؤال

Data

1; from 0; to 1; 5% ; boulder; 10% ; sand; 20%; silt

The output should look like this:

1; from 0; to 1;  5% ; boulder

1; from 0; to 1; 10%; sand

1; from 0; to 1; 20% silt
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top