作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 Oracle 11g,我很困惑第三个查询如何在下面编译。这不应该引发 ORA-00937 错误吗?其他人能否重现此内容或解释 Oracle 如何或为何忽略内联 View 中缺少 GROUP BY 子句? (不过它确实会抛出错误,只是自己运行子查询)
DROP TABLE ZZZ_DELETE_ME;
CREATE TABLE ZZZ_DELETE_ME
(
contract NUMBER(6),
lives INTEGER
);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123456,100);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123456,50);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123457,100);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123457,50);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123458,100);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123458,50);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123459,100);
INSERT INTO ZZZ_DELETE_ME (contract,lives) VALUES (123459,50);
-- query 1 returns 100 for each record (which makes sense)
SELECT contract, SUM(MAX_LIVES) TOTAL_LIVES
FROM
(
SELECT contract, MAX(lives) MAX_LIVES
FROM ZZZ_DELETE_ME
GROUP BY contract
)
GROUP BY contract;
-- query 2 returns 400 (which makes sense)
SELECT SUM(MAX_LIVES) TOTAL_LIVES
FROM
(
SELECT contract, MAX(lives) MAX_LIVES
FROM ZZZ_DELETE_ME
GROUP BY contract
);
-- query 3 returns 100 (but why? Shouldn't this throw an error?)
SELECT SUM(MAX_LIVES) TOTAL_LIVES
FROM
(
SELECT contract, MAX(lives) MAX_LIVES
FROM ZZZ_DELETE_ME
-- THERE'S NO GROUP BY HERE!
);
最佳答案
这是 Oracle 错误 5520732,已在 11.2 版中修复。如果您有 Oracle 支持帐户,您可以阅读所有相关内容。
要确认,您可以将查询更改为
SELECT SUM(MAX_LIVES) TOTAL_LIVES
FROM
(
SELECT /*+ NO_MERGE */ contract, MAX(lives) MAX_LIVES
FROM ZZZ_DELETE_ME
-- THERE'S NO GROUP BY HERE!
);
...您应该得到预期的错误。
关于sql - 为什么 Oracle 不因缺少 GROUP BY 子句而抛出错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50494820/
我是一名优秀的程序员,十分优秀!