更新时间:2023-01-20 09:23:34
这是一个不透明的操作。您可以使用 union all
执行所需的操作:
This is an unpivot operation. You can do what you want with a union all
:
select EmpNo, Location, Period1 as period, Value1 as Value
from data
union all
select EmpNo, Location, Period2 as period, Value2 as Value
from data
union all
select EmpNo, Location, Period3 as period, Value3 as Value
from data;
有些数据库直接支持unpivot以及其他方法。但是,以上是ANSI标准SQL。
Some databases have direct support for unpivot as well as other methods for doing it. However, the above is ANSI standard SQL.