sql - oracle sql 内联查询标识符无效
问题描述
我有以下 oracle sql 查询
select tren,origen,area
from (
select cod_serv tren,a.origen origen
from r_incidencias r,
(select tren,origen
from r_trenes80_e
union
select tren,origen
from k_trenes80) a
,
(select id_area_productiva area,cod_estacion estacion
from mer_est_area_prod meap
where a.tren = r.cod_serv
and meap.cod_estacion = a.origen
) f)
当我执行这句话时,我得到了错误
a.origen 标识符无效。
我希望表 mer_est_area_prod 中的字段 origen 与查询 a 中的字段 origen 相等。
在表 mer_est_area_prod 中存在字段 origen
解决方案
不能在子查询join中直接使用joined table column,可以移到子查询外的where条件
前任:
SELECT tren,origen,area
FROM
(
SELECT cod_serv tren ,a.origen origen
FROM r_incidencias r,
(
SELECT tren,origen
FROM r_trenes80_e
UNION
SELECT tren,origen
FROM k_trenes80
) a,
(
SELECT id_area_productiva area,cod_estacion estacion
FROM mer_est_area_prod meap
) f
WHERE a.tren = r.cod_serv
AND f.estacion = a.origen
)
最好使用新的 ANSI sql 连接条件,因为您尝试连接的内容很清楚
前任:
SELECT cod_serv tren ,a.origen origen, meap.id_area_productiva area
FROM r_incidencias r
INNER JOIN
(
SELECT tren,origen
FROM r_trenes80_e
UNION
SELECT tren,origen
FROM k_trenes80
) a ON a.tren = r.cod_serv
INNER JOIN mer_est_area_prod meap ON meap.cod_estacion = a.origen
推荐阅读
- javascript - 我怎么知道 2 个绝对 html 元素何时堆叠在一起
- python-3.x - 如何根据 Python 中的输入在函数内动态创建全局变量
- wordpress - 尝试在 WordPress 上添加预加载的动画和鼠标效果
- java - Spring Elasticsearch:向工作 POJO 类添加字段会导致 IllegalArgumentException:null 不是 Map
- python - 基于两个条件(x 和 y 轴)的颜色 numpy 数组
- excel - 使用递归和 MSXML Excel VBA 查找子节点
- python - Python:无法替换文本文件中的特殊/外来字符
- android - 为什么当我在安卓设备上运行我的 cocos2dx 游戏时,使用 UTF-8 字符串的 ui::Text 组件的渲染会受到限制?
- node.js - tumblr.js createPhotoPost 使用多个图像 url
- java - 无法从 START_ARRAY 令牌中反序列化“com.dckr.microsvc.model.Event”的实例