Aggregates

Aggregate functions such as sum, max etc. are readily available in Datomic's Datalog implementation. They are written in the :find clause in your query:

[:find (max ?date)
 :where
 ...]

An aggregate function collects values from multiple datoms and returns

  • A single value: min, max, sum, avg, etc.
  • A collection of values: (min n ?d) (max n ?d) (sample n ?e) etc. where n is an integer specifying the size of the collection.

count the number of movies in the database

Query:[ I give up! ]

Find the birth date of the oldest person in the database.

Query:[ I give up! ]

Given a collection of actors and (the now familiar) ratings data. Find the average rating for each actor. The query should return the actor name and the avg rating.

Query:[ I give up! ]

Input #1:

Input #2: