Cosmos DB 查询同一字段必须具有两个值的文档
Cosmos DB Querying documents that must have two values for the same field
你好,现在有点卡住了。
假设我有一个简单的 collection(可能不是很好构建...):
- id
- user_id
- application_id
- version
- [other fields]
我想获取特定 application_id 的所有 user_id,该 application_id 必须使用应用程序的两个特定版本。
如果只要求一个特定的版本,这很简单
select c.user_id from c where c.application_id='123456' and c.version='1.0'
但如果我只是尝试添加另一个版本(使用 AND 运算符),结果是空的,这是正常的。
我尝试使用 JOIN 运算符但没有成功使其工作。
还要说我的 SQL 背景又老又穷,我不会谈论 Cosmos DB SQL 特性
But I want to be able to detect user_id that have used two versions of
a specific application
也许我得到了你的 point.You 意思是你的数据如下:
A用户名有v1和v2,B用户名有v1。现在你只想 select A 因为 A 跨越 v1 和 v2。恐怕这个需求不能用单一查询来实现 sql。你可以参考下面sql:
SELECT count(c.version) as count,c.userid FROM c
where (c.version='v1' or c.version='v2')
group by c.userid
那么根据count =2
就可以知道哪个userid跨越了v1和v2。自己循环结果就好了
你好,现在有点卡住了。 假设我有一个简单的 collection(可能不是很好构建...):
- id
- user_id
- application_id
- version
- [other fields]
我想获取特定 application_id 的所有 user_id,该 application_id 必须使用应用程序的两个特定版本。
如果只要求一个特定的版本,这很简单
select c.user_id from c where c.application_id='123456' and c.version='1.0'
但如果我只是尝试添加另一个版本(使用 AND 运算符),结果是空的,这是正常的。 我尝试使用 JOIN 运算符但没有成功使其工作。
还要说我的 SQL 背景又老又穷,我不会谈论 Cosmos DB SQL 特性
But I want to be able to detect user_id that have used two versions of a specific application
也许我得到了你的 point.You 意思是你的数据如下:
A用户名有v1和v2,B用户名有v1。现在你只想 select A 因为 A 跨越 v1 和 v2。恐怕这个需求不能用单一查询来实现 sql。你可以参考下面sql:
SELECT count(c.version) as count,c.userid FROM c
where (c.version='v1' or c.version='v2')
group by c.userid
那么根据count =2
就可以知道哪个userid跨越了v1和v2。自己循环结果就好了