ORA-00907:缺少右括号-嵌套选择NOT IN

时间:2018-07-12 12:08:11

标签: sql oracle notin ora-00907

很抱歉再次发表有关该主题的文章。总共有4页的结果,因此很难磨合特定的解决方案。

谁能看到此SQL的问题吗?

SELECT evntmst_id, count(evntmst_id) AS idcount
FROM evntcond 
WHERE EVNTMST_ID NOT IN (
    SELECT DISTINCT c.EVNTMST_ID 
    FROM evntcond c 
    LEFT JOIN evntmst m 
    ON c.EVNTMST_ID = m.EVNTMST_ID
    WHERE m.EVNTMST_TYPE IN (1, 7) -- Group or Subset
    AND m.EVNTMST_ID IS NOT NULL   -- remove data integrity issues
    GROUP BY c.EVNTMST_ID
    ORDER BY c.EVNTMST_ID
)
GROUP BY EVNTMST_ID
ORDER BY count(evntmst_id) Desc

这产生 ORA-00907: missing right parenthesis

如果我使用嵌套的SELECT DISTINCT并将其替换为1,2,则一切正常。

SELECT evntmst_id, count(evntmst_id) AS idcount
FROM evntcond 
WHERE EVNTMST_ID NOT IN (
    1,2
)
GROUP BY EVNTMST_ID
ORDER BY count(evntmst_id) Desc

如果我自己运行嵌套查询,则一切正常。

SELECT DISTINCT c.EVNTMST_ID 
FROM evntcond c 
LEFT JOIN evntmst m 
ON c.EVNTMST_ID = m.EVNTMST_ID
WHERE m.EVNTMST_TYPE IN (1, 7) -- Group or Subset
AND m.EVNTMST_ID IS NOT NULL   -- remove data integrity issues
GROUP BY c.EVNTMST_ID
ORDER BY c.EVNTMST_ID

Oracle有什么功能。这是错误吗?

1 个答案:

答案 0 :(得分:1)

这似乎太复杂了。我想你打算:

SelectionChanged

这会过滤出SELECT c.evntmst_id, COUNT(c.evntmst_id) AS idcount FROM evntcond c WHERE NOT EXISTS (SELECT 1 FROM evntmst m WHERE m.EVNTMST_ID = c.EVNTMST_ID AND m.EVNTMST_TYPE IN (1, 7) ) GROUP BY EVNTMST_ID ORDER BY count(evntmst_id) DESC; ,其中有相应的“ 1”或“ 7”记录。

我应该补充一点,您的查询中没有明显的语法错误。