PL-SQL:ORA-00904-无效标识符-Select和Pivot子句中的列

PL-SQL:ORA-00904-无效标识符-Select和Pivot子句中的列,sql,oracle,pivot,Sql,Oracle,Pivot,有代码可以创建下面的输出,并且在我的生命周期中无法调试pivot,以使每个pivot都有自己的列。我删除了“ORDER”和“GROUP”子句,并尝试将其作为轴心,但它仍然会产生“ORA-00904:“Tax Status”:无效标识符”。取决于我做了什么,它会在最初的选择,有时,其他人会对轴生气,如果我使用单引号或双引号 支点与之斗争: pivot ( min('Total Value') for ("Tax Status") in ('Exempt

有代码可以创建下面的输出,并且在我的生命周期中无法调试pivot,以使每个pivot都有自己的列。我删除了“ORDER”和“GROUP”子句,并尝试将其作为轴心,但它仍然会产生“ORA-00904:“Tax Status”:无效标识符”。取决于我做了什么,它会在最初的选择,有时,其他人会对轴生气,如果我使用单引号或双引号

支点与之斗争:

pivot
(
    min('Total Value') 
    for ("Tax Status")
    in ('Exempt from Taxation' as "Exempt", 'Taxable' as "Taxable", 'Tax Agreement - Operator of a Public Utility' as "Tax Agreement",
    '"Assessed Person" Tax Agreement' as "Tax Agreement", 'Grant in Place of Tax' as "Grant", 'Council Tax Cancellation or Refund' as "Council Cancel/Refund")
)
SELECT "Team", "Tax Status", sum("Total Value") "Total Value"
FROM 
    (
    select (A.account_roll_number) "Roll Number", ALU.DESCRIPTION "Assessor", A.account_total_property_value as "Total Value",
    TaxLU.DESCRIPTION "Tax Status",
    
    CASE
        when A.assessor_id in ('ATHENDRATA', 'BRTHOMPSON', 'FTACIUNE', 'HPHILLIPS', 'JDCHU', 'JRYOUNG1', 'MHARTMANN', 'NCCHAN', 'RLEE5', 'SBERZINS') then 'Industrial'
        when A.assessor_id in ('ASMTDWA','ASMTEB', 'ASMTWS', 'BBROCKLEBANK', 'CCHICHAK', 'CYMAU', 'GJONES4', 'IYPAU', 'JTGREER', 'KHOUSTON', 'LGMORRISON', 'MMCKENZIE1', 'MWALZ', 'SKUANG', 'STBAZIN', 'TKNGUYEN1', 'ASHIELDS') then 'Single Residential'
        when A.assessor_id in ('BTANG', 'CMACMILLAN1', 'DGENCARELLI', 'EWU1', 'JWEHLER', 'LMDUNBAR', 'LWONG4', 'MGULOWSKA', 'RLEE1', 'SHAMMOUD', 'SLTURNER', 'YWANG') then 'Multi Residential'
        when A.assessor_id in ('CMULENGA', 'EPOPOVICS', 'GFULLER', 'IMCDERMOTT', 'JERMUBE', 'JNSTEVENSON', 'JPLEPINE', 'KBUCKRY', 'KDALMHJELL', 'NPHAM1', 'PGKERSEY', 'SMSAMPLE') then 'Special Purpose and Land'
        when A.assessor_id in ('ASMTHN', 'DCARSON', 'DLIDGREN', 'DMCCORD', 'EBORISENKO', 'HYAU1', 'MCTRIMBLE', 'RJTHARAKAN', 'TBJOHNSON1', 'VWONG1', 'WGIBBS', 'YYE', 'AVPETERS') then 'Office'
        when A.assessor_id in ('AKEAST', 'BLTHOMPSON', 'BNELSON1', 'JCRUJI', 'JWONG1', 'KGARDINER', 'KMHAUT', 'NTNGUYEN', 'RTLUCHAK', 'SGILL3', 'THEGER1', 'TJLUDLOW', 'ZRGEIB') then 'Retail'
        else 'Other'
    END as "Team"
    
    from REP_DBA.AB000_ACCOUNT A
    
    join REP_DBA.LU_ASMT_ASSIGN_ASSESSOR ALU
    on A.assessor_id = ALU.code
    
    -- Decode the Tax Status from the LU Table
    join rep_dba.LU_ASMT_ACCT_TAX_STATUS TaxLU
    on TaxLU.CODE = A.account_tax_status
    
    where A.rollyear = :rollyear
    and A.account_type = 'P'
    and A.account_status = 'AP'
    and A.account_total_property_value is not null
    ORDER BY account_total_property_value DESC
)
GROUP BY "Team", "Tax Status"
ORDER BY "Team"
产生以下输出的工作查询:

pivot
(
    min('Total Value') 
    for ("Tax Status")
    in ('Exempt from Taxation' as "Exempt", 'Taxable' as "Taxable", 'Tax Agreement - Operator of a Public Utility' as "Tax Agreement",
    '"Assessed Person" Tax Agreement' as "Tax Agreement", 'Grant in Place of Tax' as "Grant", 'Council Tax Cancellation or Refund' as "Council Cancel/Refund")
)
SELECT "Team", "Tax Status", sum("Total Value") "Total Value"
FROM 
    (
    select (A.account_roll_number) "Roll Number", ALU.DESCRIPTION "Assessor", A.account_total_property_value as "Total Value",
    TaxLU.DESCRIPTION "Tax Status",
    
    CASE
        when A.assessor_id in ('ATHENDRATA', 'BRTHOMPSON', 'FTACIUNE', 'HPHILLIPS', 'JDCHU', 'JRYOUNG1', 'MHARTMANN', 'NCCHAN', 'RLEE5', 'SBERZINS') then 'Industrial'
        when A.assessor_id in ('ASMTDWA','ASMTEB', 'ASMTWS', 'BBROCKLEBANK', 'CCHICHAK', 'CYMAU', 'GJONES4', 'IYPAU', 'JTGREER', 'KHOUSTON', 'LGMORRISON', 'MMCKENZIE1', 'MWALZ', 'SKUANG', 'STBAZIN', 'TKNGUYEN1', 'ASHIELDS') then 'Single Residential'
        when A.assessor_id in ('BTANG', 'CMACMILLAN1', 'DGENCARELLI', 'EWU1', 'JWEHLER', 'LMDUNBAR', 'LWONG4', 'MGULOWSKA', 'RLEE1', 'SHAMMOUD', 'SLTURNER', 'YWANG') then 'Multi Residential'
        when A.assessor_id in ('CMULENGA', 'EPOPOVICS', 'GFULLER', 'IMCDERMOTT', 'JERMUBE', 'JNSTEVENSON', 'JPLEPINE', 'KBUCKRY', 'KDALMHJELL', 'NPHAM1', 'PGKERSEY', 'SMSAMPLE') then 'Special Purpose and Land'
        when A.assessor_id in ('ASMTHN', 'DCARSON', 'DLIDGREN', 'DMCCORD', 'EBORISENKO', 'HYAU1', 'MCTRIMBLE', 'RJTHARAKAN', 'TBJOHNSON1', 'VWONG1', 'WGIBBS', 'YYE', 'AVPETERS') then 'Office'
        when A.assessor_id in ('AKEAST', 'BLTHOMPSON', 'BNELSON1', 'JCRUJI', 'JWONG1', 'KGARDINER', 'KMHAUT', 'NTNGUYEN', 'RTLUCHAK', 'SGILL3', 'THEGER1', 'TJLUDLOW', 'ZRGEIB') then 'Retail'
        else 'Other'
    END as "Team"
    
    from REP_DBA.AB000_ACCOUNT A
    
    join REP_DBA.LU_ASMT_ASSIGN_ASSESSOR ALU
    on A.assessor_id = ALU.code
    
    -- Decode the Tax Status from the LU Table
    join rep_dba.LU_ASMT_ACCT_TAX_STATUS TaxLU
    on TaxLU.CODE = A.account_tax_status
    
    where A.rollyear = :rollyear
    and A.account_type = 'P'
    and A.account_status = 'AP'
    and A.account_total_property_value is not null
    ORDER BY account_total_property_value DESC
)
GROUP BY "Team", "Tax Status"
ORDER BY "Team"
轴前输出


PIVOT
中的列必须使用双引号,如下所示:

Select * from
(
SELECT "Team", "Tax Status", sum("Total Value") "Total Value"
FROM 
    (
    select (A.account_roll_number) "Roll Number", ALU.DESCRIPTION "Assessor", A.account_total_property_value as "Total Value",
    TaxLU.DESCRIPTION "Tax Status",

    CASE
        when A.assessor_id in ('ATHENDRATA', 'BRTHOMPSON', 'FTACIUNE', 'HPHILLIPS', 'JDCHU', 'JRYOUNG1', 'MHARTMANN', 'NCCHAN', 'RLEE5', 'SBERZINS') then 'Industrial'
        when A.assessor_id in ('ASMTDWA','ASMTEB', 'ASMTWS', 'BBROCKLEBANK', 'CCHICHAK', 'CYMAU', 'GJONES4', 'IYPAU', 'JTGREER', 'KHOUSTON', 'LGMORRISON', 'MMCKENZIE1', 'MWALZ', 'SKUANG', 'STBAZIN', 'TKNGUYEN1', 'ASHIELDS') then 'Single Residential'
        when A.assessor_id in ('BTANG', 'CMACMILLAN1', 'DGENCARELLI', 'EWU1', 'JWEHLER', 'LMDUNBAR', 'LWONG4', 'MGULOWSKA', 'RLEE1', 'SHAMMOUD', 'SLTURNER', 'YWANG') then 'Multi Residential'
        when A.assessor_id in ('CMULENGA', 'EPOPOVICS', 'GFULLER', 'IMCDERMOTT', 'JERMUBE', 'JNSTEVENSON', 'JPLEPINE', 'KBUCKRY', 'KDALMHJELL', 'NPHAM1', 'PGKERSEY', 'SMSAMPLE') then 'Special Purpose and Land'
        when A.assessor_id in ('ASMTHN', 'DCARSON', 'DLIDGREN', 'DMCCORD', 'EBORISENKO', 'HYAU1', 'MCTRIMBLE', 'RJTHARAKAN', 'TBJOHNSON1', 'VWONG1', 'WGIBBS', 'YYE', 'AVPETERS') then 'Office'
        when A.assessor_id in ('AKEAST', 'BLTHOMPSON', 'BNELSON1', 'JCRUJI', 'JWONG1', 'KGARDINER', 'KMHAUT', 'NTNGUYEN', 'RTLUCHAK', 'SGILL3', 'THEGER1', 'TJLUDLOW', 'ZRGEIB') then 'Retail'
        else 'Other'
    END as "Team"

    from REP_DBA.AB000_ACCOUNT A

    join REP_DBA.LU_ASMT_ASSIGN_ASSESSOR ALU
    on A.assessor_id = ALU.code

    -- Decode the Tax Status from the LU Table
    join rep_dba.LU_ASMT_ACCT_TAX_STATUS TaxLU
    on TaxLU.CODE = A.account_tax_status

    where A.rollyear = :rollyear
    and A.account_type = 'P'
    and A.account_status = 'AP'
    and A.account_total_property_value is not null
    -- ORDER BY account_total_property_value DESC -- not needed
  )
GROUP BY "Team", "Tax Status"
)
pivot
(
    min("Total Value")  -- here
    for ("Tax Status")
    in ('Exempt from Taxation' as "Exempt", 'Taxable' as "Taxable", 
        'Tax Agreement - Operator of a Public Utility' as "Tax Agreement", -- duplicate
        '"Assessed Person" Tax Agreement' as "Tax Agreement 1", -- changed alias, added 1
        'Grant in Place of Tax' as "Grant", 'Council Tax Cancellation or Refund' as "Council Cancel/Refund")
)

干杯

我试过了,但还没有成功。我是否将总和(“总值”)“总值”保留在选择框中?我也把min放进去了,但现在我认为这可能是不正确的。还要将任何“TotalValue”重命名为“TotalValue”以保持一致。感谢您的帮助。我敢肯定它就快到了,从你那里复制了信息。我看到了select*from()和group by的想法。现在在第1行第8列显示“00918.00000-”列定义不明确“…”错误,因此它不喜欢子句
中的select*from.Got it..pivot子句-->作为“税务协议”“
使用了两次。更改其中一个名称。请参阅更新的答案。非常感谢!我看到了相应的更改/重命名,运行良好。非常感谢。