tsc*_*ein 1 sql oracle sql-like oracle12c
我不太明白......
有人可以给我一个提示,说明为什么查询B + C的结果不会累加到A?
我首先想到的是,由于拼写错误,下划线(应该是10)在B和C之间不匹配,但在复制/粘贴后我有点无奈.A的结果高于B + C的总和.
在语句B和C中是否存在某种我不知道的隐含的不同?
-- statement A
select count(*) from mytable;
-- statement B
select count(*) from mytable where mycolumn like '__________';
-- statement C
select count(*) from mytable where mycolumn not like '__________';
Run Code Online (Sandbox Code Playgroud)
如果mycolumn有一些带有NULL值的行,那么这些行将从两个LIKE和NOT LIKE子句中排除.
因此,这两个陈述应该是相同的:
SELECT (select count(*) from mytable where mycolumn like '__________')
+ (select count(*) from mytable where mycolumn not like '__________')
+ (select count(*) from mytable where mycolumn IS NULL)
FROM DUAL
-- is equal to
select count(*) from mytable;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
205 次 |
| 最近记录: |