0

我收到以下语句的主题行中引用的 ORA-00933 错误:

 select
 (select count(name) as PLIs
 from (select
   a.name,
   avg(b.list_price) as list_price
 from 
   crm.prod_int a, crm.price_list_item b
 where 
   a.row_id = b.product_id
   and a.x_sales_code_3 <> '999'
   and a.status_cd not like 'EOL%'
   and a.status_cd not like 'Not%'
   and a.x_sap_material_code is not null
 group by a.name)
 where list_price = 0)
 /
 (select count(name) as PLIs
 from (select
   a.name,
   avg(b.list_price) as list_price
 from 
   crm.prod_int a, crm.price_list_item b
 where 
   a.row_id = b.product_id
   and a.x_sales_code_3 <> '999'
   and a.status_cd not like 'EOL%'
   and a.status_cd not like 'Not%'
   and a.x_sap_material_code is not null
 group by a.name))
 as result from dual;

我已经尝试删除别名作为其他帖子中建议的解决方案,但这并没有改变问题。有任何想法吗?谢谢。

4

3 回答 3

1

如果您在 SQLPlus 中运行它,它可能会误解语句终止符的第一列中的除法运算符。其他工具也可能容易受到影响。尝试移动除法运算符,例如where list_price = 0) \

于 2013-05-15T15:13:47.673 回答
0

答案是错误的,请参阅@Ben 的评论

不必命名子查询...仅当它们被直接引用时,即如果在完整查询中有多个具有相同名称的列


必须命名子查询。考虑改变:

from (select
      ...
      group by a.name)

至:

from (select
      ...
      group by a.name) SubQueryAlias
于 2013-05-15T15:05:18.937 回答
0

这并不能直接回答您的问题,但我认为可以简化查询:

select case PLIs when 0 then -1 else PLIs_noprice / PLIs end from (
 select 
  count(name) as PLIs,
  count(case list_price when 0 then 1 end) as PLIs_noprice
 from (
  .... your innermost subselect, up to "group by" goes here ...
 )
)

不知何故,我无法在此处粘贴您的实际子选择代码,出现“提交您的帖子时出错”......未经测试,因为我没有您的表格。

于 2013-05-15T15:34:33.177 回答