在数据透视块中获取无效标识符ORA-00904

问题描述 投票:0回答:2

我在枢轴代码块的以下查询中获取无效的标识符,请帮助解决此问题

select cif_id,
       to_char(tran_date,'MON-YYYY'),
       part_tran_type ,
       tran_amt
from CUSTOM.HTD_OCT_DEC19 H,
            tbaadm.gam 
pivot
(count(1),
 sum(tran_amt)
for **part_tran_type** in ('D','C'))
where h.tran_date ='24-DEC-2019' 
  and h.PSTD_FLG='Y' 
  and h.DEL_FLG='N' 
  and gam.cust_id='D46478329' 
  and h.cust_id=gam.cust_id 
  and rpt_code in ('20211','20212','20270','20271','20410','20420','20440',
                   '20501','20502','20504','60202');
sql oracle pivot
2个回答
0
投票

我认为您没有正确使用PIVOT。尝试使用以下代码:

SELECT * FROM
    (
        SELECT
            CIF_ID,
            TO_CHAR(TRAN_DATE, 'MON-YYYY') as TRAN_DATE,
            PART_TRAN_TYPE,
            TRAN_AMT
        FROM CUSTOM.HTD_OCT_DEC19 H, TBAADM.GAM
        WHERE
            H.TRAN_DATE = '24-DEC-2019'
            AND H.PSTD_FLG = 'Y'
            AND H.DEL_FLG = 'N'
            AND GAM.CUST_ID = 'D46478329'
            AND H.CUST_ID = GAM.CUST_ID
            AND RPT_CODE IN (
                '20211', '20212', '20270', '20271', '20410', '20420',
                '20440', '20501', '20502', '20504', '60202'
            )
    ) PIVOT (
        COUNT ( 1 ) AS CT, SUM ( TRAN_AMT ) AS SM
        FOR PART_TRAN_TYPE
        IN ( 'D', 'C' )
    )

干杯!


0
投票

按如下所示更改查询后现在可以工作:

select * from ( select gam.cif_id,to_char(tran_date,'MON-YYYY'),h.part_tran_type ,h.tran_amt from CUSTOM.HTD_OCT_DEC19 H,tbaadm.gam where h.tran_date ='24-DEC-2019' and h.PSTD_FLG='Y' and h.DEL_FLG='N' and gam.cif_id='D46478329' and h.cust_id=gam.cust_id and h.rpt_code in ('20211','20212','20270','20271','20410','20420','20440','20501','20502','20504','60202') ) pivot ( count(1) as TXNCOUNT, sum(tran_amt) as TXNSUM for part_tran_type in ('D' as DEBIT,'C' as CREDIT) );

© www.soinside.com 2019 - 2024. All rights reserved.