带有 WHERE 子句的 Azure Cosmos SQL 结果没有意义
Azure Cosmos SQL results with WHERE clause doesn't make sense
我 运行 对我的 Cosmos 数据库进行了一些查询,结果似乎没有意义。当我知道我应该得到一些结果时,我得到了一些查询的 0 个结果。以下是查询结果:
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' -- 165229
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source='five9' -- 132100
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source<>'five9' -- 0
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source=null -- 0
我的目标是统计 source
属性不等于 'five9' 的所有项目。但是该查询(如上所示)returns 计数为 0。如您所见,在第一个查询中,该分区中的项目总数为 165,229。从第二个查询中,此分区中 source
等于 'five9' 的项目总数为 132,100。常识告诉我,源不等于'five9'的项数应该是33129。为什么我的查询显示 0?
要记住的一件事是,当我检查原始形式的项目时,没有 source='five9'
的项目根本没有 source
属性。这会导致这种行为吗?此外,ownerTime
是分区键。
这里是一小部分数据:
SELECT c.id,c.ownerTime,c.source from c where c.ownerTime='2010775021_202009'
...
{
"id": "L2n8D4c4GOFQTUA",
"ownerTime": "2010775021_202009"
},{
"id": "3524zXL55zQmQ8qk",
"ownerTime": "2010775021_202009",
"source": "five9"
}
...
请试试这个sql:
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and (not IS_DEFINED(c.source) or c.source<>'five9')
我 运行 对我的 Cosmos 数据库进行了一些查询,结果似乎没有意义。当我知道我应该得到一些结果时,我得到了一些查询的 0 个结果。以下是查询结果:
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' -- 165229
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source='five9' -- 132100
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source<>'five9' -- 0
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and c.source=null -- 0
我的目标是统计 source
属性不等于 'five9' 的所有项目。但是该查询(如上所示)returns 计数为 0。如您所见,在第一个查询中,该分区中的项目总数为 165,229。从第二个查询中,此分区中 source
等于 'five9' 的项目总数为 132,100。常识告诉我,源不等于'five9'的项数应该是33129。为什么我的查询显示 0?
要记住的一件事是,当我检查原始形式的项目时,没有 source='five9'
的项目根本没有 source
属性。这会导致这种行为吗?此外,ownerTime
是分区键。
这里是一小部分数据:
SELECT c.id,c.ownerTime,c.source from c where c.ownerTime='2010775021_202009'
...
{
"id": "L2n8D4c4GOFQTUA",
"ownerTime": "2010775021_202009"
},{
"id": "3524zXL55zQmQ8qk",
"ownerTime": "2010775021_202009",
"source": "five9"
}
...
请试试这个sql:
SELECT COUNT(c.id) from c where c.ownerTime='2010775021_202009' and (not IS_DEFINED(c.source) or c.source<>'five9')