如何将colums转换为sql中的行

时间:2021-10-11 23:42:44

I have a table with the following values

我有一个包含以下值的表

如何将colums转换为sql中的行

and I need the output values as below.

我需要输出值如下。

如何将colums转换为sql中的行

Please help to arrive the code

请帮忙到达代码

1 个解决方案

#1


0  

It's not pretty, but this would work:

它不漂亮,但这可行:

select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence

#1


0  

It's not pretty, but this would work:

它不漂亮,但这可行:

select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence