Aggregate in where clause

This one is for googlers

[:find ?tag ?n
 :where
 [(datomic.api/q (quote [:find ?e (count ?post) :where [?post :post/tag ?e]]) $) [[?tag ?n]]]
 [(> ?n 3)]]

RICH: You can do this and similar (SQL ‘HAVING’-like) things by chaining together queries, i.e. use the result of an aggregating query as the argument to a further narrowing query. source

Dustin,

Thanks for putting this here.
I’ve also often referred to this as nested query or sub-query

-M

1 Like