【问题标题】:Datomic query for maximum of aggregated value聚合值最大值的原子查询
【发布时间】:2015-02-27 03:07:20
【问题描述】:

假设我有实体 author 和许多相关的 book 实体。 获取书籍数量最多的作者的查询是什么?

【问题讨论】:

    标签: datomic datalog


    【解决方案1】:

    好的。由于我自己找到了答案 - 我将其发布在这里以防有人搜索:

    解决方案是构建两个 datomic 查询,将第一个的输出传递到第二个。

    (->>
      (d/q '[:find (count ?b) ?a :where [?a :author/books ?b]] db)
      (d/q '[:find (max ?count) ?a :in $ [?count ?a]] db))
    

    据我所知,这是在 datomic 中处理不太重要的查询的常用方法 - 将其拆分为几个子查询并链接在一起,让数据库完成其工作。

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 2015-04-12
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多