N1QL聚合查询Couchbase
我正在尝试编写一个查询,该查询将聚合源和目标组合的一周中给定日期的文档结果。
存储桶中的文档如下所示
{
"source": "test-source-1",
"target": "test-target-1",
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-06": {
"day_of_week": "Sunday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-13": {
"day_of_week": "Sunday",
"result-1": 190.8181818181818,
"result-2": {
"low_limit": 30.0,
"high_limit": 30.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 6.0,
"high_limit": 6.0
}
}
}
{
"source": "test-source-2",
"target": "test-target-2",
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-06": {
"day_of_week": "Sunday",
"result-1": 400,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-13": {
"day_of_week": "Sunday",
"result-1": 400,
"result-2": {
"low_limit": 30.0,
"high_limit": 30.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 6.0,
"high_limit": 6.0
}
}
}
如果我们在所有文档中查询 where day_of_week = Saturday ,则预期结果应如下:
[
{
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
}
"source": "test-source-1",
"target": "test-target-1"
},
{
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"source": "test-source-2",
"target": "test-target-2"
}
]
到目前为止,我有以下查询,但它返回所有 day_of_week。 我知道我正在选择 b.* ,它将在所有日子中返回,只是不确定如何每天过滤掉它,即仅周六或周日
SELECT b.*
FROM `history-dummy`.`_default`.`node-to-node` AS b
WHERE ANY v IN OBJECT_VALUES(b) SATISFIES v.`day_of_week`="Saturday" END;
任何帮助将不胜感激。谢谢
I'm trying to write a query that will aggregate results for documents for given day of week for a combination of source and target.
Documents in the bucket look like this
{
"source": "test-source-1",
"target": "test-target-1",
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-06": {
"day_of_week": "Sunday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-13": {
"day_of_week": "Sunday",
"result-1": 190.8181818181818,
"result-2": {
"low_limit": 30.0,
"high_limit": 30.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 6.0,
"high_limit": 6.0
}
}
}
{
"source": "test-source-2",
"target": "test-target-2",
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-06": {
"day_of_week": "Sunday",
"result-1": 400,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-13": {
"day_of_week": "Sunday",
"result-1": 400,
"result-2": {
"low_limit": 30.0,
"high_limit": 30.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 6.0,
"high_limit": 6.0
}
}
}
And the expected result should be as follows if we are Querying for where day_of_week = Saturday in all documents:
[
{
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 467.5326086956522,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
}
"source": "test-source-1",
"target": "test-target-1"
},
{
"2022-03-05": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"2022-03-12": {
"day_of_week": "Saturday",
"result-1": 300,
"result-2": {
"low_limit": 21.0,
"high_limit": 14.0
},
"result-3": {
"low_limit": 1.0,
"high_limit": 1.0
},
"result-4": {
"low_limit": 3.0,
"high_limit": 2.0
}
},
"source": "test-source-2",
"target": "test-target-2"
}
]
I have the following query till now but it returns all the day_of_week.
I know I am selecting b.* which will return for all days just unsure how to filter this out for each day i.e only Saturday or Sunday
SELECT b.*
FROM `history-dummy`.`_default`.`node-to-node` AS b
WHERE ANY v IN OBJECT_VALUES(b) SATISFIES v.`day_of_week`="Saturday" END;
Any help would be greatly appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加源、目标
Add source, target