简体   繁体   English

Oracle SQL无效标识符

[英]Oracle SQL Invalid Identifier

I'm trying to run this query but I get "ORA-00904: "Z1"."LONGITUDE": invalid identifier" 我正在尝试运行此查询,但收到“ ORA-00904:“ Z1”。“ LONGITUDE”:无效的标识符“

Is there a way to rewrite this so I have access to that column in the exists subquery? 有没有一种方法可以重写它,以便我可以访问exist子查询中的该列? Or is there generally a better way to achieve what I'm trying to do? 还是一般来说,有一种更好的方法可以实现我想要做的事情?

Thanks 谢谢

select zip, count(UNIQUE address_id) LOCATIONS
from records 
inner join addresses a using(address_id) 
inner join zip_coords z1 using(zip)
where exists
(
  select 1 from (
    select distance(z1.latitude, z1.longitude, z2.latitude, z2.longitude) d
    from zip_coords z2
    where z2.zip in (
      select zip from available_zips
    )
  ) where d <= 50
)
GROUP BY ZIP

Your problem is that you can't descend that many levels into your subquery. 您的问题是您不能将这么多级别归入子查询。 I might have missed something from skimming over your query but could: 我可能会漏掉一些查询内容,但可能会:

select 1 from (
    select distance(z1.latitude, z1.longitude, z2.latitude, z2.longitude) d
    from zip_coords z2
    where z2.zip in (
      select zip from available_zips
    )
  ) where d <= 50

not be rewritten as: 不能改写为:

SELECT 1
FROM zip_coords z2
WHERE z2.zip IN (
  SELECT zip FROM available_zips
)  
AND distance(z1.latitude, z1.longitude, z2.latitude, z2.longitude) <= 50
select zip, count(UNIQUE address_id) LOCATIONS
from records 
inner join addresses a using(address_id) 
inner join zip_coords z1 using(zip)
where 
(
    select min(distance(z1.latitude, z1.longitude, z2.latitude, z2.longitude)) d
    from zip_coords z2
    inner join available_zips using(zip)
) <= 50
GROUP BY ZIP

I have to warn you, I do not know how this will affect performance of the query. 我必须警告您,我不知道这将如何影响查询性能。

instead of using: 而不是使用:

inner join zip_coords z1 using(zip)

Try including zip_coords z1 as part of the FROM clause and include the joins in the WHERE. 尝试将zip_coords z1作为FROM子句的一部分,并将联接包括在WHERE中。 You should then be able to access z1 from your subquery. 然后,您应该能够从子查询访问z1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM