我运行查询时收到以下错误消息:
ORA-00904:" ACCNT":无效的标识符
00904. 00000 - "%s:无效标识符"
*原因:
*行动:
行错误:33列:29
以下是我正在运行的代码:
select
pdl.business_unit as BU,
pdl.deptid as BR,
pb.in_service_dt as IN_SERVICE_DATE,
pdl.asset_id as ASSET_ID,
pa.descr as DESCRIPTION,
pa.serial_id as SERIAL_NUMBER,
pdl.account as ACCNT,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end as DEPTID,
MAX(CASE WHEN (pdl.trans_in_out = 'O') then pdl.deptid END) as ACCT_FROM,
MAX(CASE WHEN (pdl.trans_in_out = 'I') then pdl.deptid END) as ACCT_TO
From ps_dist_ln pdl,
ps_book pb,
ps_asset pa
where
pdl.business_unit = 'A0465'
and pdl.fiscal_year = '2014'
and pdl.asset_id = '000000000151'
and pdl.accounting_period = '12'
and pdl.trans_type = 'RCT'
and pdl.distribution_type = 'FA'
and pdl.book = 'PERFORM'
and pdl.asset_id = pb.asset_id and pdl.business_unit = pb.business_unit
and pdl.asset_id = pa.asset_id and pdl.business_unit = pa.business_unit
GROUP BY
BU,
BR,
IN_SERVICE_DATE,
ASSET_ID,
DESCRIPTION,
SERIAL_NUMBER,
ACCNT,
DEPTID
我无法弄清楚为什么会收到此错误。所有字段名称和别名看起来都是正确的。任何帮助将不胜感激。谢谢你的帮助。
答案 0 :(得分:3)
GROUP BY无法识别SELECT子句中定义的别名。
如果您的SELECT语句说明了这一点:
SELECT
pdl.business_unit as BU,
pdl.deptid as BR,
pb.in_service_dt as IN_SERVICE_DATE,
pdl.asset_id as ASSET_ID,
pa.descr as DESCRIPTION,
pa.serial_id as SERIAL_NUMBER,
pdl.account as ACCNT,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end AS DEPTID
然后你的GROUP BY语句应该这样说:
GROUP BY
pdl.business_unit,
pdl.deptid,
pb.in_service_dt,
pdl.asset_id,
pa.descr,
pa.serial_id,
pdl.account,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end