行转列:

SELECT *   
FROM   src_table   
UNPIVOT (param_value FOR param_name IN (product_color AS 'product_color', product_type AS 'product_type', is_intelligent AS 'is_intelligent'));

 

列转换:

 select *  from (

select flow,xx from tab

)   a pivot (max(value) for enname in ( 'flow' flow ,'xx')) b order by id ";

 

 

我自己的测试

oracle 11g行转列  列转行

注意:建表插入的时候varchar字符型必须要加上'',

 insert into s1 values('yuan','english',80);

 

SELECT * FROM s1
PIVOT ( MAX(score) for subject IN( 'chinese'  chinese , 'math'  math  , 'english'  english ) )

注意这里max的是分数,in的是subject  

oracle 11g行转列  列转行

 返回来

 

  SELECT * FROM 
( SELECT * FROM s1 PIVOT ( MAX(score) for subject IN( 'chinese' chinese , 'math' math , 'english' english ) ) ) UNPIVOT ( score FOR subject IN ( chinese , math , english ) )

 

注意这里 最后一句的in chinese 之类,chinese不需要加''

oracle 11g行转列  列转行

相关文章:

  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-09-21
  • 2021-09-01
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2021-04-10
  • 2022-01-12
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案