嵌套查询 - 错误 - 值太多

时间:2017-07-19 22:20:10

标签: sql oracle11g

我正在尝试获取在子查询中重复多次的所有值并将它们提取到另一个查询,但我无法使其工作,这是我的代码:

select
 transaction_id, 
 hashed
 from  table1
 where hashed in (select hashed, count(1) 
                                        from data_headers1 
                                        where virtual_table_id = 5237260000000006162 
                                        and import_ts >= timestamp '2017-07-01 00:00:00' 
                                        group by hashed 
                                        having count(1) > 1) ;

这意味着我想要查看每个具有2个或更多相同散列信息的transaction_id。

2 个答案:

答案 0 :(得分:0)

我想我的问题已经解决了:

select 
 h.hashed,
 h.TRANSACTION_ID
 from table1 h inner join
 (select hashed cc, count(1) 
     from table1 where virtual_table_id = 5237260000000006162 
     and import_ts >= timestamp '2017-07-01 00:00:00' 
     group by hashed 
     having count(1) > 1) ca
  on ca.cc = h.hashed 
  where h.VIRTUAL_TABLE_ID  = 5237260000000006162;

它向我发送了我正在寻找的信息......

答案 1 :(得分:0)

只需从您从内部查询获得的输出中分离哈希值,因为哈希值只能与单个值进行比较。

select
transaction_id, 
hashed
from  table1
where hashed in (select hashed from(select hashed, count(1) 
                                    from data_headers1 
                                    where virtual_table_id = 5237260000000006162 
                                    and import_ts >= timestamp '2017-07-01 00:00:00' 
                                    group by hashed 
                                    having count(1) > 1));

这应该有用。