oracle行转列

1.构造虚拟表

select 'a' 字段1,'100' 字段2 from dual
union all
select 'b' 字段2,'200' 字段2 from dual

2.虚拟表为

字段1       字段2

a               100

b               200

3.行转列

with query1 as
(
select 'a' 字段1,'100' 字段2 from dual
union all
select 'b' 字段2,'200' 字段2 from dual
)
select 字段1,
max(case when 字段1='a' then 字段2 else null end) as a,
max(case when 字段1='b' then 字段2 else null end) as b
from query1
group by 字段1

4.结果表为

字段1      A         B

a            100

b                        100


扫描二维码关注公众号,回复: 882642 查看本文章


猜你喜欢

转载自blog.csdn.net/swiftlinlei/article/details/79863965
今日推荐