Aggregated WHERE condition in Cypher query

52 views
Skip to first unread message

kiteflo

unread,
Nov 6, 2012, 12:02:01 PM11/6/12
to ne...@googlegroups.com
Hi guys,

I'm just wondering whether there is a way of aggregating several WHERE conditions, sth. like this is what we require...:

...WHERE (offer.nodeState = 'ACTIVE') AND count(rcat) > 3...

But this one results in "Can't use aggregate functions in the WHERE clause", is there anyway of achieving/working around this using a special Cypher trick?

Thanx in advance, Florian;

Andres Taylor

unread,
Nov 6, 2012, 12:27:28 PM11/6/12
to ne...@googlegroups.com
What is rcat in your example?

You can do it using WITH, but there might be an even better solution for it, depending on the rest of your query.

Andrés

--
 
 



--
The best way to ask for Cypher help: http://console.neo4j.org/usage.html 

kiteflo

unread,
Nov 6, 2012, 12:34:45 PM11/6/12
to ne...@googlegroups.com
Hi Andres,

here's the full query which gives an idea about rcat...any help highly appreciated...

START spat=node:GEO_INDEX('withinDistance:[47.4661494,7.8577615,50.0]'),package=node:cardpckgIDX('id:ea81242e-b12f-4e86-8c23-70cce1b2d156') MATCH offer<-[rr?:REVIEW]-review,spat-[r1:MANUAL_SPATIAL_CONNECT]->loc-[r2:GEOFIES]->offer,package-[pcat:INCLUDES_CATEGORY]->category<-[rcat?:CATEGORY_LINK]-offer WHERE (offer.nodeState = 'ACTIVE') AND count(rcat) > 3 RETURN distinct offer, avg(review.rating), count(review), count(rcat) ORDER BY count(rcat) DESC SKIP 0 LIMIT 8

Andres Taylor

unread,
Nov 6, 2012, 12:45:57 PM11/6/12
to ne...@googlegroups.com
You are actually using things on the other side of rcat, so using pattern expressions won't work. You can do this with WITH, like this:

START spat=node:GEO_INDEX('withinDistance:[47.4661494,7.8577615,50.0]'),
      package=node:cardpckgIDX('id:ea81242e-b12f-4e86-8c23-70cce1b2d156')
MATCH offer<-[rr?:REVIEW]-review,
      spat-[r1:MANUAL_SPATIAL_CONNECT]->loc-[r2:GEOFIES]->offer,
      package-[pcat:INCLUDES_CATEGORY]->category<-[rcat?:CATEGORY_LINK]-offer 
WHERE offer.nodeState = 'ACTIVE'
WITH distinct offer, avg(review.rating) as average_review, count(review) as no_of_reviews, count(rcat) as count_rcat
WHERE count_rcat > 3
RETURN offer, average_review, no_of_reviews, count_rcat
ORDER BY count_rcat DESC 
SKIP 0 
LIMIT 8

HTH,

Andrés
Reply all
Reply to author
Forward
0 new messages