修改密码

请输入密码
请输入密码 请输入8-64长度密码 和 email 地址不相同 至少包括数字、大写字母、小写字母、半角符号中的 3 个
请输入密码
提交

修改昵称

当前昵称:
提交

申请证书

证书详情

Please complete this required field.

  • Ultipa Graph V4

Standalone

Please complete this required field.

Please complete this required field.

服务器的MAC地址

Please complete this required field.

Please complete this required field.

取消
申请
ID
产品
状态
核数
申请天数
审批时间
过期时间
MAC地址
申请理由
审核信息
关闭
基础信息
  • 用户昵称:
  • 手机号:
  • 公司名称:
  • 公司邮箱:
  • 地区:
  • 语言:
修改密码
申请证书

当前未申请证书.

申请证书
Certificate Issued at Valid until Serial No. File
Serial No. Valid until File

Not having one? Apply now! >>>

ProductName CreateTime ID Price File
ProductName CreateTime ID Price File

No Invoice

v5.0
搜索
    v5.0

      GROUP BY

      概述

      GROUP BY从句可用来指定对最终表分组时使用的分组键。 The GROUP BY clause allows you to specify the set of grouping keys to be used during grouping on the final table.

      <return statement> ::= 
        "RETURN" [ "DISTINCT" ] { <"*"> | <return item list> }
        [ <group by clause> ]
                                       
      <group by clause> ::= "GROUP BY" <grouping key list>
      
      <grouping key list> ::=
          <grouping key> [ { "," <grouping key> }... ]
      
      <grouping key> ::= <binding variable>
      

      详情

      • 每个分组键必须为绑定变量。如果分组键并非已有绑定变量,有以下两种选择:

        • 使用AS重命名:如果分组键是最终结果表的一部分,可以使用关键词AS重命名对应列。
        • 使用LET:也可在RETURN语句前使用LET语句,为分组键定义一个新变量,确保其能在分组时使用。
      • 分完组后,每组仅返回一条记录。

      • 有分组操作时,RETURN语句中的任何聚合操作都应用于分完的组。

      • Each grouping key must be a binding variable. If the desired grouping key is not already an existing binding variable, you have two options:

        • Renaming using AS: If the grouping key is part of the final result table, you can rename the corresponding column using the AS keyword.
        • Using LET: Alternatively, you can use the LET statement to define a new variable for the grouping key before the RETURN statement, ensuring it is available for grouping.
      • After grouping, only one record in each group will be returned.

      • When grouping is involved, any aggregation operation in the RETURN statement is applied to each group after the grouping is done.

      示例图集

      以下示例根据该图集运行:

      在空图集中运行以下语句创建示例图集:

      INSERT (alex:Student {_id: 's1', name: 'Alex', gender: 'male'}),
             (susan:Student {_id: 's2', name: 'Susan', gender: 'female'}),
             (alex2:Student {_id: 's3', name: 'Alex', gender: 'female'}),
             (art:Course {_id: 'c1', name: 'Art', credit: 13}),
             (literature:Course {_id: 'c2', name: 'Literature', credit: 15}),
             (alex)-[:Take {year: 2024, term: 'Spring'}]->(art),
             (alex2)-[:Take {year: 2023, term: 'Fall'}]->(art),
             (susan)-[:Take {year: 2023, term: 'Fall'}]->(art),
             (susan)-[:Take {year: 2023, term: 'Spring'}]->(literature)
      

      根据单个分组键分组

      MATCH (:Student)->(c:Course)
      RETURN c GROUP BY c
      

      结果:c

      _id _uuid schema
      values
      c1 Sys-gen Course {name: "Art", credit: 13}
      c2 Sys-gen Course {name: "Literature", credit: 15}

      根据列别名分组

      本条查询中,分组键Namen.name的列别名: In this query, the grouping key Name is the column alias of n.name:

      MATCH (n:Student)
      RETURN n.name AS Name GROUP BY Name
      

      结果:

      Name
      Alex
      Susan

      以下查询会引发语法错误,这是因为分组键n.name并非绑定变量:

      MATCH (n:Student)
      RETURN n.name GROUP BY n.name
      

      根据LET定义的变量分组

      本条查询中,分组键GenderLET语句定义:

      MATCH (n:Student)
      LET Gender = n.gender
      RETURN n GROUP BY Gender
      

      结果:

      n
      (:Student {_id: "s1", gender: "male", name: "Alex"})
      (:Student {_id: "s3", gender: "female", name: "Alex"})

      一下查询会引发语法错误,这是因为分组键n.gender并非绑定变量:

      MATCH (n:Student)
      RETURN n GROUP BY n.gender
      

      分组Grouping with Aggregation

      MATCH (n:Student)
      RETURN n.name AS Name, count(n) GROUP BY Name
      

      结果:

      Name count(n)
      Alex 2
      Susan 1

      Grouping by Multiple Keys

      MATCH ({_id: "c1"})<-[e:Take]-()
      RETURN e.year AS Y, e.term AS T GROUP BY Y, T
      

      结果:

      Year Term
      2023 Fall
      2024 Spring
      请完成以下信息后可下载此书
      *
      公司名称不能为空
      *
      公司邮箱必须填写
      *
      你的名字必须填写
      *
      你的电话必须填写
      *
      你的电话必须填写