Aggregate in where clause


#1

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


#2

Dustin,

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

-M