我的SQL数据库中有一个资源和一个订单表,我有以下SQL查询:
Select resource.id, resource.name from resource
inner join orders on orders.res_id = resource.id
where orders.markup < 1000 and
resource.id = 100
此工作正常,并在我的视图中显示已过滤的ID和NAME字段。但是,我还想在视图中看到orders.markup列。我尝试了以下方法:
Select resource.id, resource.name, orders.* from resource, orders
inner join orders on orders.res_id = resource.id
where orders.markup < 1000 and
resource.id = 100
这失败了:
ORA-00904: "RESOURCE"."ID": invalid identifier
答案 0 :(得分:2)
试试这个:
Select resource.id, resource.name, orders.markup from resource
inner join orders on orders.res_id = resource.id
where orders.markup < 1000 and
resource.id = 100
答案 1 :(得分:1)
您的代码中存在错误 - 您使用资源,订单同时使用内部联接...从查询中删除,订单,反之亦然 - 删除内部联接
样品:
create table "resource" (id integer, name varchar2(50));
create table orders (res_id int, markup integer, name varchar2(50));
select res.id, res.name, orders.*
from "resource" res
inner join orders on orders.res_id = res.id
where orders.markup < 1000 and
res.id = 100