使用ALIAS按顺序排列

时间:2014-02-03 10:55:34

标签: sql oracle oracle11g oracle-sqldeveloper

我正在运行以下查询:

     Select * From (SELECT pt.prod_desc AS"PROD_DESC",
  (
  CASE
 WHEN pt.prod_level='2'
THEN 'Product'
WHEN pt.prod_level='4'
THEN 'Sub-Product'
WHEN pt.prod_level='5'
THEN 'Service'
ELSE 'N/A'
 END)         AS"PROD_LEVEL",
 prod_id      AS "PROD_ID",
 isactive     AS "IsActive",
updt_usr_sid AS "UPDT_USR_SID",
 updt_ts      AS "UPDT_TS",
 (
  CASE
WHEN pt.prod_level='5'
THEN parent_prod_id
ELSE NULL
  END) AS ".SUB_PROD_ID",
  (
CASE
WHEN pt.prod_level='5'
THEN
  (SELECT prod_desc FROM dims_prod_type A WHERE A.prod_id= pt.parent_prod_id
  )
ELSE 'N/A'
   END ) AS ".SUB_PROD_DESC",
  (
  CASE
   WHEN pt.prod_level='4'
THEN parent_prod_id
WHEN pt.prod_level='5'
THEN
  (SELECT parent_prod_id
  FROM dims_prod_type A
  WHERE A.prod_id= pt.parent_prod_id
  )
ELSE NULL
END) AS ".PRNT_PROD_ID",
(
CASE
  WHEN pt.prod_level='4'
THEN
  (SELECT prod_desc FROM dims_prod_type A WHERE A.prod_id=pt.parent_prod_id
  )
WHEN pt.prod_level='5'
THEN
  (SELECT prod_desc
  FROM dims_prod_type A
  WHERE A.prod_id IN
    (SELECT B.parent_prod_id
    FROM dims_prod_type B
    WHERE b.prod_id=pt.parent_prod_id
    )
  )
ELSE 'N/A'
END)AS ".PRNT_PROD_DESC"
FROM dims_prod_type pt)A
  WHERE A.PRNT_PROD_ID is not null
 ORDER BY A.SUB_PROD_ID ASC

然而它正在抛出

        SQL Error: ORA-00904: "A"."SUB_PROD_ID": invalid identifier
      00904. 00000 -  "%s: invalid identifier"

错误。我在这里做错了吗?我尝试使用group by / even尝试别名As--?作为A但似乎没有任何作用。请帮我解决这个问题,因为我不确定我以错误的方式执行了什么步骤。

1 个答案:

答案 0 :(得分:2)

删除别名中的点 - AS ".SUB_PROD_ID",变为AS "SUB_PROD_ID",; AS ".PRNT_PROD_DESC"变为AS "PRNT_PROD_DESC"。或者,如果您确实坚持在别名中添加点,请将最后一行更改为ORDER BY A.".SUB_PROD_ID" ASC