使用pivot更改列名称

时间:2016-06-13 09:05:51

标签: oracle pivot columnname

WITH prod AS
(SELECT points_spent,price_of_item,channel FROM transaction_history
where channel=?
)
SELECT *
from prod pivot (sum(points_spent) for (channel) in ('AP' as rpts_admin_portal , 'MB' as rpts_member_portal ),
SUM(price_of_item) FOR (channel) IN ('AP' fifty_percent_cashback_price,'MB' retail_price)

我尝试使用pivot动态显示列名。这里我需要在上面显示两列名称,例如当用户通过成员门户网站购买项目时需要显示rpts_member_portal,如果管理员门户网站需要显示rpts_admin_portal。 price_of_item也差不多。但是我只能在oracle的一个专栏中实现。如何为price_of_item做这个。帮助我克服这个问题。

实际数据

points_spent    price_of_item  channel
============    =============  ==============
100             100            AP
50              100            MB

预期结果集是渠道是否为管理员门户

rpts_admin_portal   fifty_percent_cashback_price  channel
=================   ============================= ==========
100                 100                           AP

如果是成员门户网站,则预期结果集为

rpts_member_portal   retail_price                 channel
=================   ============================= ==========
50                  50                            MB

0 个答案:

没有答案
相关问题