Return 'biggest fan of a tag'

Hi, I want to match blogs that have most like interaction with certain tags (in the example I used dog) but posted in it less than 10 times. How can I achieve that?

Currently, I get this error message

Invalid use of aggregating function count(...) in this context (line 6, column 7 (offset: 210))
"WHERE COUNT(posted) < 10"

Query

MATCH (b:Blog)-[r:liked]-(p:Post)-[:tagged]-(t:Tag)
WHERE t.content = "dog"
WITH b, COUNT(r) as interaction_count

MATCH (b:Blog)-[posted:posted_by]-(:Post)-[:tagged]-(t:Tag)
WHERE COUNT(posted) < 10

RETURN b, interaction_count
ORDER BY interaction_count DESC
LIMIT 10

Hi @magicaltoast !
You can't do an aggregation of data and use it inside the WHERE clause, first, you'd need to do the aggregation and then use it to filter the data. Also, you can chain the two MATCHes and only use one time the WITH clause, like this:

MATCH (b:Blog)-[r:liked]-(:Post)-[:tagged]-(t:Tag),
(b)-[posts:posted_by]-(:Post)-[:tagged]-(t)
WHERE t.content = "dog"
WITH b, COUNT(r) AS interaction_count, COUNT(posts) AS post_count
WHERE post_count < 10
RETURN b, interaction_count
ORDER BY interaction_count DESC
LIMIT 10

Also, it's a good practice to state the direction of your relationships when they can only go one way, and only omit them when this is not the case. Hope this helps!