aws redshift 中的 ILIKE 和 NOT ILIKE 与总数不同

Elm*_*Elm 3 sql null count amazon-redshift

我在 amazon redshift 中运行了以下三个查询:

select count(*)  
from t1  
Run Code Online (Sandbox Code Playgroud)

计数为 1554。

select count(*)  
from t1  
where  
    item_name ilike "blue"  
Run Code Online (Sandbox Code Playgroud)

计数是62。

select count(*)  
from t1  
where  
    item_name not ilike "blue"  
Run Code Online (Sandbox Code Playgroud)

计数是85。

最后两个 (62 + 85) 应该等于 1554。我错过了什么?

Erw*_*ter 6

双引号用于标识符:"myColumn"
单引号用于值:'value'

您的示例与这些基本语法规则相矛盾。

此外,您没有考虑NULL值,这些值都不符合:

item_name ilike 'blue'
Run Code Online (Sandbox Code Playgroud)

也没有:

item_name not ilike 'blue'
Run Code Online (Sandbox Code Playgroud)

你得到什么:

SELECT count(*)                             AS all_rows
     , count(item_name  ~~* 'blue' OR NULL) AS item_name_blue
     , count(item_name !~~* 'blue' OR NULL) AS item_name_not_blue
     , count(item_name)                     AS item_name_not_null
     , count(item_name IS NULL OR NULL)     AS item_name_null
FROM   t1;
Run Code Online (Sandbox Code Playgroud)

~~* .. 内部 Postgres 运算符 for ILIKE
!~~*.. 内部 Postgres 运算符 for NOT ILIKE
(注意:运算符优先级略有不同。)