0

很抱歉再次发布有关此主题的信息。这有 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

甲骨文怎么了。这是一个错误吗?

4

1 回答 1

1

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

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;

这会过滤掉EVNTMST_ID具有相应“1”或“7”记录的记录。

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

于 2018-07-12T12:15:15.703 回答