java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

11. NEO4j CQL ORDER BY

NEO4j CQL ORDER BY 使用简介

用来排序的 ASC DESC 适用

//清空数据 
MATCH (n) DETACH DELETE n
//创建数据
CREATE (:Person {name: 'Anne', age: 34, length: 172})
CREATE (:Person {name: 'Bob', age: 37})
CREATE (:Person {name: 'Jim', age: 26, length: 185})

NEO4j CQL ORDER BY 按一个属性排序

MATCH (n) RETURN n.name, n.age ORDER BY n.name
╒════════╤═══════╕
│"n.name"│"n.age"│
╞════════╪═══════╡
│"Anne"  │34     │
├────────┼───────┤
│"Bob"   │37     │
├────────┼───────┤
│"Jim"   │26     │
└────────┴───────┘

NEO4j CQL ORDER BY 按多个属性排序

MATCH (n) RETURN n.name, n.age ORDER BY n.age, n.name
╒════════╤═══════╕
│"n.name"│"n.age"│
╞════════╪═══════╡
│"Jim"   │26     │
├────────┼───────┤
│"Anne"  │34     │
├────────┼───────┤
│"Bob"   │37     │
└────────┴───────┘

NEO4j CQL ORDER BY 按ID排序

MATCH (n)
RETURN n.name, n.age
ORDER BY id(n)
╒════════╤═══════╕
│"n.name"│"n.age"│
╞════════╪═══════╡
│"Anne"  │34     │
├────────┼───────┤
│"Bob"   │37     │
├────────┼───────┤
│"Jim"   │26     │
└────────┴───────┘

NEO4j CQL ORDER BY 按条件排序

按属性多少的顺序来排
MATCH (n) RETURN n.name, n.age, n.length ORDER BY keys(n)
╒════════╤═══════╤══════════╕
│"n.name"│"n.age"│"n.length"│
╞════════╪═══════╪══════════╡
│"Anne"  │34     │172       │
├────────┼───────┼──────────┤
│"Jim"   │26     │185       │
├────────┼───────┼──────────┤
│"Bob"   │37     │null      │
└────────┴───────┴──────────┘

NEO4j CQL ORDER BY 倒过来排序

MATCH (n) RETURN n.name, n.age ORDER BY n.name DESC
╒════════╤═══════╕
│"n.name"│"n.age"│
╞════════╪═══════╡
│"Jim"   │26     │
├────────┼───────┤
│"Bob"   │37     │
├────────┼───────┤
│"Anne"  │34     │
└────────┴───────┘

NEO4j CQL ORDER BY 为NULL值排序

MATCH (n)
RETURN n.length, n.name, n.age
ORDER BY n.length

╒══════════╤════════╤═══════╕
│"n.length"│"n.name"│"n.age"│
╞══════════╪════════╪═══════╡
│172       │"Anne"  │34     │
├──────────┼────────┼───────┤
│185       │"Jim"   │26     │
├──────────┼────────┼───────┤
│null      │"Bob"   │37     │
└──────────┴────────┴───────┘

NEO4j CQL ORDER BY 在一个WITH条件语句内排序

MATCH (n) 
WITH n 
ORDER BY n.age 
RETURN collect(n.name) AS names
╒════════════════════╕
│"names"             │
╞════════════════════╡
│["Jim","Anne","Bob"]│
└────────────────────┘


This entry was posted in 数据库 and tagged . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/neo4j-cql-order-by/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

Leave a Reply