除以 2 个 SELECT 语句 - "SQL 命令未正确结束"错误



我得到主题行中引用的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;

我已经尝试删除别名建议的解决方案在其他帖子,但这并没有改变问题。什么好主意吗?谢谢。

如果在SQLPlus中运行此操作,则可能会错误地解释语句结束符的第一列中的除法操作符。其他工具也可能受到影响。尝试移动除法运算符,例如:where list_price = 0)

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

子查询不需要命名…只有当它们被直接引用时,即在完整查询中有多个具有相同名称的列


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

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

:

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

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

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 ...
 )
)

不知何故,我不能粘贴你的实际子选择代码在这里,得到"错误提交你的帖子"…没有测试,因为我没有你的表

相关内容

  • 没有找到相关文章

最新更新