如何在Cypher中将“空”结果按降序返回?

时间:2018-12-14 08:40:22

标签: neo4j cypher

如何在Cypher中对BY进行排序以将“空”结果以降序排列回去?通过documentation,空结果排在第一位,降序排列。

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, n.numberOfVotes 
ORDER BY n.numberOfVotes DESC 
LIMIT 7

1 个答案:

答案 0 :(得分:0)

您可以在coalesce中将ORDER BY的null设为零。

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, n.numberOfVotes 
ORDER BY coalesce(n.numberOfVotes,0) DESC 
LIMIT 7

或者您可以简单地合并返回的属性。

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, coalesce(n.numberOfVotes,0) 
ORDER BY n.numberOfVotes DESC 
LIMIT 7