7

この種のクエリをデータ型で書くことは可能ですか?

  • 最年長の子供の名前を見つける
  • 体格指数 (体重 / 身長) が最も低い人を見つける
4

1 に答える 1

8
[:find (max ?tuple) :where 
    [?k :kid/age ?age] 
    [?k :kid/name ?name] 
    [(vector ?age ?name) ?tuple]

Note:

  • the order of attributes in expression (vector ?age ?name) matters

  • the query returns single result while we might expect a collection because there may be many kids of age that is the maximum in the set. You can use (max n ?tuple) to achieve that.

See also the Aggregates Returning Collections section in http://docs.datomic.com/query.html

If you have something more specific in mind, provide more details in the question and include your schema.

于 2013-04-12T15:01:12.163 に答える