sql - 如何根据 ComosDb 中聚合函数的结果对查询结果进行排序?

标签 sql azure sql-order-by azure-cosmosdb aggregate-functions

我使用 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/

相关文章:

azure - 如何在 DBT 中创建 Python 宏以用于外部 API 调用和 JDBC 连接

mysql - 如何只在满足特定条件的情况下现场下订单?

mysql - 如何用另一个表的值更新表

php - 获取最近7天内的注册用户

MYSQL ERROR 1248 我卡住了

c# - 流畅的 NHibernate 查询 : OrderBy column of joined table

zend-framework2 - 如何在 Zend2 的删除查询中使用 limit 和 order by

mysql - 使用当前记录加上另一个表记录的总和从一个表更新记录

azure - 部署包含 key 保管库中存储的证书的 ARM 模板时出错

azure - 如何使用 GitHub Branch 作为 Azure DevOps Pipelines 的参数?