使用比较操作时透视查询问题

时间:2017-12-14 09:24:10

标签: oracle pivot

当我尝试运行以下查询时,我收到此错误

  

ORA-00917:缺少逗号   00917. 00000 - “缺少逗号”   *原因:
  *动作:行错误:26列:22

查询:

select * from 
(select 'india',po.team,pa.NAME,pa.userid,me.amount as RN
from
port po,
switch pa,
merchant me
where po.SEQNO=pa.SEQNO
and (pa.SEQNO=me.SEQNO and RN is not null)) 
PIVOT (
count(*) for RN in(RN<1,RN-20.01)
)

1 个答案:

答案 0 :(得分:0)

  

我希望使用数据透视逻辑

将百分比列显示为&lt; = 1,介于10到20之间和> 20之间

在初始子查询中使用case语句:

select *
from   (
  select *
  from   (
    select 'india',
           po.team,
           pa.NAME,
           pa.userid,
           CASE
           WHEN me.amount <= 1              THEN '<1'
           WHEN me.amount BETWEEN 10 AND 20 THEN '10-20'
           WHEN me.amount > 20              THEN '>20'
           END as RN
    from   port po
           INNER JOIN switch pa
           ON ( po.SEQNO=pa.SEQNO )
           INNER JOIN merchant me
           ON ( pa.SEQNO=me.SEQNO )
  )
  where  RN is not null
) PIVOT (
  count(*) for RN in( '<1', '10-20', '>20' )
);