简体   繁体   中英

Neo4j Cypher order by

example query

START
  n = node(*)
RETURN
  n
ORDER BY
  n.activeTo DESC

But n.activeTo = 0 mean active at the moment. This rows should be first. In SQL order is

ORDER BY
  IF(activeTo = 0, 0, 1) ASC,
  activeTo DESC

How to write it in Cypher ?

You can use a CASE clause in your ORDER BY clause:

START
  n = node(*)
RETURN
  n
ORDER BY
  CASE n.activeTo WHEN 0 THEN 0 ELSE 1 END ASC,
  n.activeTo DESC

I set up an example console here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM