oracle 数据库,表的行类转换问题(50分)

  • 主题发起人 主题发起人 l_diamond
  • 开始时间 开始时间
L

l_diamond

Unregistered / Unconfirmed
GUEST, unregistred user!
: 原始表:表名:ACTCOSTDETAIL<br>结构如下:<br>&nbsp;项目名称 本月金额 &nbsp;上月金额 &nbsp; 下月金额<br>&nbsp; &nbsp;a &nbsp; &nbsp; &nbsp; &nbsp; 118 &nbsp; &nbsp; &nbsp; &nbsp;998 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;766<br>&nbsp; &nbsp; b &nbsp; &nbsp; &nbsp; &nbsp;876 &nbsp; &nbsp; &nbsp; &nbsp;333 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;222<br><br>想实现表结构如下:<br>&nbsp;名称 &nbsp; &nbsp; &nbsp;项目名称 金额<br>本月金额 &nbsp; a &nbsp; &nbsp; &nbsp; &nbsp; 118<br>上月金额 &nbsp; &nbsp;a &nbsp; &nbsp; &nbsp; &nbsp;998<br>下月金额 &nbsp; &nbsp; a &nbsp; &nbsp; &nbsp; 766<br>本月金额 &nbsp; b &nbsp; &nbsp; &nbsp; &nbsp; 876<br>上月金额 &nbsp; &nbsp;b &nbsp; &nbsp; &nbsp; &nbsp;333<br>下月金额 &nbsp; &nbsp;b &nbsp; &nbsp; &nbsp; 222
 
select '本月金额' 名称,项目名称, 本月金额 金额 from ACTCOSTDETAIL<br>union all<br>select '上月金额' 名称,项目名称, 上月金额 金额 from ACTCOSTDETAIL<br>union all<br>select '下月金额' 名称,项目名称, 下月金额 金额 from ACTCOSTDETAIL<br>order by 项目名称
 
select '本月金额' as 名称,项目名称, 本月金额 as 金额 from ACTCOSTDETAIL<br>union <br>select '上月金额' as 名称,项目名称, 上月金额 as 金额 from ACTCOSTDETAIL<br>union <br>select '下月金额' as 名称,项目名称, 下月金额 as 金额 from ACTCOSTDETAIL<br>order by 项目名称
 
搞定,谢谢你们
 
后退
顶部