【发布时间】:2017-02-08 19:34:51
【问题描述】:
这些结果让我大吃一惊。在子查询中包装查询时,group by 子句会突然删除所有具有特定值的行。
谁能帮我弄清楚这可能会发生什么?
简而言之,这是我的问题,我不明白最后的结果:
with my_cte as (
select complex stuff from tables
)
select checktype from my_cte group by checktype
这将返回 2 行:PRE、POST。
with my_cte as (
select complex stuff from tables
)
select distinct checktype from my_cte
这也返回 2 行:PRE,POST。
with my_cte as (
select complex stuff from tables
)
select * from (
select distinct checktype from my_cte
)
这也返回 2 行:PRE,POST
with my_cte as (
select complex stuff from tables
)
select * from (
select checktype from my_cte group by checktype
)
这只返回 1 行!前。为什么?
如果我使用另一个 CTE 而不是子查询,也会发生同样的事情。
为什么oracle中的子查询会突然删除某个值的所有行?
Oracle 版本:
Oracle Database 12c 企业版 12.1.0.2.0 - 64 位生产版
【问题讨论】:
-
你能在这里添加带有表结构的示例数据吗?
-
我在 Oracle 11g 上做了一个快速测试:
with my_cte as ( select 'PRE' AS checktype from dual UNION ALL select 'POST' AS checktype from dual ) select * from ( select checktype from my_cte group by checktype ),我无法重现你的问题,结果是正确的 -
抛出我的查询并提供结果
-
发布一个可重现的测试用例,否则它没有发生。