=====1
select * from ( SELECT
REMAIN_POOR_FAM as 返贫人口
,POOR_FAM as 贫困人口
,REMAIN_POOR_POP as 返贫人数
,POOR_POP as 贫困人数
FROM R_ANALYSIS_HOME_PAGE_Y R
WHERE STAT_TIME = 2019
AND PAC = 460000000000)
unpivot( 值 for 属性 in (返贫人口,贫困人口,返贫人数,贫困人数)) b
原例
SELECT
INDUSTRY_EXCP1_FAM AS 有纳税
, INDUSTRY_EXCP2_FAM AS 户籍问题
, decode(INDUSTRY_EXCP1_FAM,0,1,round(INDUSTRY_EXCP1_APPEAL_FAM/INDUSTRY_EXCP1_FAM ,4))*100 有纳税1
,decode(INDUSTRY_EXCP2_FAM,0,1,round(INDUSTRY_EXCP2_APPEAL_FAM/INDUSTRY_EXCP2_FAM ,4))*100 户籍问题1
from
R_DW_INDUSTRY_FAM_M t
WHERE STAT_TIME = 201906
AND PAC = 460000000000
=====2
select TEST1,字段名,值,RATE from (
SELECT '测试' as TEST1
,INDUSTRY_EXCP1_FAM AS 有纳税
, INDUSTRY_EXCP2_FAM AS 户籍问题
, decode(INDUSTRY_EXCP1_FAM,0,1,round(INDUSTRY_EXCP1_APPEAL_FAM/INDUSTRY_EXCP1_FAM ,4))*100 有纳税1
,decode(INDUSTRY_EXCP2_FAM,0,1,round(INDUSTRY_EXCP2_APPEAL_FAM/INDUSTRY_EXCP2_FAM ,4))*100 户籍问题1
from
R_DW_INDUSTRY_FAM_M t
WHERE STAT_TIME = 201906
AND PAC = 460000000000
)unpivot(值 for 字段名 in (有纳税,户籍问题 )) b
unpivot (Rate for 字段名1 in (有纳税1,户籍问题1 )) c
WHERE 字段名=substr(字段名1,1,length(字段名1)-1)
====3
select 字段名,值,RATE from (
SELECT
INDUSTRY_EXCP1_FAM AS 有纳税
, INDUSTRY_EXCP2_FAM AS 户籍问题
, decode(INDUSTRY_EXCP1_FAM,0,1,round(INDUSTRY_EXCP1_APPEAL_FAM/INDUSTRY_EXCP1_FAM ,4))*100 有纳税1
,decode(INDUSTRY_EXCP2_FAM,0,1,round(INDUSTRY_EXCP2_APPEAL_FAM/INDUSTRY_EXCP2_FAM ,4))*100 户籍问题1
from
R_DW_INDUSTRY_FAM_M t
WHERE STAT_TIME = 201906
AND PAC = 460000000000
)unpivot(值 for 字段名 in (有纳税,户籍问题 )) b
unpivot (Rate for 字段名1 in (有纳税1,户籍问题1 )) c
WHERE 字段名=substr(字段名1,1,length(字段名1)-1)