sql我只提供一需要改的sql,具体如下,写表已经经过替换:
select t.id, a as a,0 as LOC,col,col1,col2,col3
from tabne_name t
where a is not null
union all
select t.id,b as a,1 as LOC,col,col1,col2,col3
from tabne_name t
where b is not null
union all
select t.id,c as a,2 as LOC,col,col1,col2,col3
from tabne_name t
where c is not null
改写后的sql如下
select id,new_vales,case when col_name='A' then 0case when col_name='B' then 1
case when col_name='C' then 2 end as loc,col,col1,col2,col3
(select * from
(select id, a as a,b,c,col,col1,col2,col3 from table_name where a is not null or b is not null or c is not null)
unpivot(new_values for col_name in(a,b,c)))