Oracle SQL IN-Clause使用Subselect抛出错误

时间:2017-10-17 09:39:16

标签: sql oracle greatest-n-per-group in-clause ora-00600

所以这就是我的问题: 我得到了这个SQL语句

SELECT a.ID,a.CONTENTOF 
FROM MLMDATA.PV_STORAGE a
WHERE 1=1  
AND ID IN (113312,114583,114581,113472,114585,114580,113314)
AND a.SEQ = (SELECT MAX(b.SEQ) FROM MLMDATA.PV_STORAGE b where a.ID = b.ID) 

但我现在的问题是,我收到错误:

ORA-00600: Internal Error Code, Arguments: [qernsRowP], [1], [], [], [], [], [], [], [], [], [], []

我似乎无法找到一种方法来选择这些只选择最高SEQUENZE的ID ... 我已经创建了一个View,只显示了最高的SEQ,但是它没有工作...... 我有点沮丧,因为据我所知,之前的SQL工作并且突然无法工作。

任何人都知道问题可能是什么?

2 个答案:

答案 0 :(得分:0)

请尝试此查询:

SELECT a.ID,a.CONTENTOF FROM MLMDATA.PV_STORAGE a
INNER JOIN
    (SELECT ID, CONTENTOF, MAX(SEQ) AS SEQ FROM MLMDATA.PV_STORAGE 
    where ID IN (113312,114583,114581,113472,114585,114580,113314)
    GROUP BY ID, CONTENTOF) b 
ON a.id = b.id AND a.SEQ = b.SEQ

答案 1 :(得分:0)

尝试窗口功能:

select id, contentof
from (
  select id, contentof, 
         row_number() over (partition by id order by seq desc) as rn
  FROM MLMDATA.PV_STORAGE a
  where id IN (113312,114583,114581,113472,114585,114580,113314)
) 
where rn = 1;