我使用 Cosmos Db,并且需要按 COUNT 的结果对结果进行排序。
我更喜欢直接在 Cosmosdb 查询的输出中对结果进行排序,而不是每次自己对结果进行排序(或为其创建服务)。
在 Azure 的文档资源管理器中,我对 AggregateEvent 集合执行以下请求:
SELECT * FROM (
SELECT COUNT(1) AS AlarmCount, a.AlarmType FROM AggregatedEvent a
WHERE a.AlarmType != null and a.Prom > 0
GROUP BY a.AlarmType ) AS g
ORDER BY g.AlarmCount
它会产生以下错误消息:
Identifier 'AlarmCount' could not be resolved.
如果我使用另一个属性来排序 g.AlarmType(文档中存在的一个属性),则会执行排序。
仅当您有办法使用 CosmosDb 归档排序时,请添加答案。
最佳答案
截至 2023 年 6 月,仍不支持此功能。 Microsoft 的文档在此处定义了限制:https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-group-by
The GROUP BY clause does not allow any of the following:
- Aliasing properties or aliasing system functions (aliasing is still allowed within the SELECT clause)
- Subqueries
- Aggregate system functions (these are only allowed in the SELECT clause)
关于sql - 如何根据 ComosDb 中聚合函数的结果对查询结果进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58973333/