Order By 函数

类似于 SQL,ORDER BY 可以进行升序 (ASC) 或降序 (DESC) 排序并返回结果,并且它只能在 PIPE 语句 (|) 中使用。

  1. ORDER BY <expression> [ASC | DESC] [, <expression> [ASC | DESC] ...]

如果没有指明 ASC 或 DESC,ORDER BY 将默认进行升序排序。

示例

  1. nebula> FETCH PROP ON player 100,101,102,103 YIELD player.age AS age, player.name AS name | ORDER BY age, name DESC;
  2. -- 4 个点并将他们以 age 从小到大的顺序排列,如 age 相同,则 name 按降序排列。
  3. -- 返回如下结果:
  4. ======================================
  5. | VertexID | age | name |
  6. ======================================
  7. | 103 | 32 | Rudy Gay |
  8. --------------------------------------
  9. | 102 | 33 | LaMarcus Aldridge |
  10. --------------------------------------
  11. | 101 | 36 | Tony Parker |
  12. --------------------------------------
  13. | 100 | 42 | Tim Duncan |
  14. --------------------------------------

(使用方法参见 FETCH 文档)

  1. nebula> GO FROM 100 OVER follow YIELD $$.player.age AS age, $$.player.name AS name | ORDER BY age DESC, name ASC;
  2. -- 从点 100 出发查找其关注的球员,返回球员的 age nameage 按降序排列,如 age 相同,则 name 按升序排列。
  3. -- 返回如下结果:
  4. ===========================
  5. | age | name |
  6. ===========================
  7. | 36 | Tony Parker |
  8. ---------------------------
  9. | 33 | LaMarcus Aldridge |
  10. ---------------------------
  11. | 25 | Kyle Anderson |
  12. ---------------------------