【发布时间】:2020-04-22 15:02:50
【问题描述】:
我想根据 count() = 1 的 count() 查询的结果使用 in 运算符创建查询。请参阅下面的查询。
select count(*), pr.oid
join jrtepiperun pr on pr.oid = it.oid
join xownsparts x on x.oidorigin = pr.oid
having count(*) = 1
group by pr.oid;
此查询成功返回总共 1589 行 where count(*) = 1 for each row and pr.oid 变化。我现在想根据 pr.oid 结果创建另一个查询,如下所示。
select * from jpipelinesystem pl
join xsystemhierarchy x on x.oidorigin = pl.oid
join jrtepiperun pr on pr.oid = x.oiddestination
where pr.oid
in
(
select count(*), pr.oid from
rtrprdb.jrtepiperun pr
join rtrprdb.xownsparts x on x.oidorigin = pr.oid
having count(*) = 1
group by pr.oid
);
但是,这会返回一个错误,指出值太多。
ORA-00913: 值过多
00913. 00000 - “值太多”
*原因:
*行动:
行错误:20 列:1
如何将第一个查询的 pr.oid 结果用于第二个查询?请注意,我需要有两列,因为我想要一个 count(*) = 1 的条件。
【问题讨论】: