Cypher Neo4j ORDER BY DESC request
2 answers
The error is returned because you cannot order by aggregation directly in Cypher. To order any aggregate, you need to use the WITH clause .
So your query should be (assuming you want to list titles for each actor in each genre):
MATCH (Movie {genre:"Action"})<-[:ACTS_IN]-(Person)
RETURN Person.name, Movie.genre, COUNT(Movie.title)
WITH Person.name AS name, Movie.genre AS genre, COLLECT(Movie.title) AS titles
RETURN name, genre, titles
ORDER BY LENGTH(titles) DESC
LIMIT 100
The 100 limit has now changed its behavior, so you probably want to move it to the query:
MATCH (Movie {genre:"Action"})<-[:ACTS_IN]-(Person)
RETURN Person.name, Movie.genre, COUNT(Movie.title)
WITH Person, Movie
LIMIT 100
WITH Person.name AS name, Movie.genre AS genre, COLLECT(Movie.title) AS titles
RETURN name, genre, titles
ORDER BY LENGTH(titles) DESC
Also: for your queries to run well, you must have a pointer to the Movie.genre property and you must inject labels for the movie and the person.
+1
source to share