[英]Select all the rows with same id and same value in another column without using having clause
我有一个带有多个文档的容器的 cosmos DB。 我想获取具有相同属性值的所有 id。 因为它是 Cosmos,所以我不能使用 having 子句。
例如:如果有一个带有架构的容器,
{
"id": 1,
"source": "online",
"type": "login"
},
{
"id": 1,
"source": "online",
"type": "login"
},
{
"id": 2,
"source": "online",
"type": "login"
},
{
"id": 2,
"source": "In store",
"type": "login"
}
我想要所有源值都相同且“在线”的 id。 所以在上面的例子中,它应该只返回“id”为 1。
这个请求选择了所有根本没有其他来源类型的ID,只选择那些在线的
select distinct(id), source
from(
select id, source
from your_table as t
WHERE NOT EXISTS (SELECT id
FROM your_table
WHERE source != 'online'
AND your_table.id = t.id))x
-- 如果最后需要使用这个WHERE x.id IS NOT NULL
结果:
| id | source
|:---- |:------:
| 1 | online
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.