Neo4j Graph Database Fundamentals · 课时

使用 RETURN 返回并塑造结果

掌握 Cypher 的 RETURN 子句,对图查询的输出进行投影、设置别名和塑形。

第 4 / 4 课13 个步骤

使用 RETURN 返回并塑造结果 是 CoddyKit 上的免费 Neo4j Graph Database Fundamentals 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Neo4j Graph Database Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What RETURN Does

Every read query that produces output ends with a RETURN clause. It defines exactly which values come back to you.

Think of RETURN as the projection step of your query.

MATCH (p:Person)
RETURN p;

Returning Specific Properties

Instead of whole nodes, you can return individual properties using dot notation. This keeps results lean.

MATCH (p:Person)
RETURN p.name, p.age;

Aliasing with AS

Use AS to rename a returned column. This makes output clearer and is essential when returning computed values.

MATCH (p:Person)
RETURN p.name AS personName, p.age AS years;

Returning Relationships

You can return the relationship variable too, not just nodes. This is useful when you need relationship properties.

MATCH (a:Person)-[r:FRIEND]->(b:Person)
RETURN a.name, type(r), b.name;

Computed Expressions

RETURN can contain expressions: arithmetic, string functions, and more.

MATCH (p:Person)
RETURN p.name, p.age * 12 AS ageInMonths;

DISTINCT Results

Add DISTINCT to remove duplicate rows from the output, just like in SQL.

MATCH (p:Person)-[:LIVES_IN]->(c:City)
RETURN DISTINCT c.name;

Returning Literals

You can return constant values and labels for readability or debugging.

RETURN 'Hello Cypher' AS greeting, 1 + 1 AS sum;

Returning Multiple Patterns

A single RETURN can combine values from many matched variables, building rich rows.

MATCH (u:User)-[:PLACED]->(o:Order)
RETURN u.name, o.id, o.total;

Working with Functions

Useful functions in RETURN include id(), labels(), type(), and toUpper().

MATCH (p:Person)
RETURN labels(p) AS nodeLabels, toUpper(p.name) AS upperName;

Returning a Whole Path

Capture a path in a variable and return it to inspect the full chain of nodes and relationships.

MATCH path = (a:Person {name: 'Alice'})-[:FRIEND*1..2]->(b)
RETURN path;

Keeping Output Clean

Best practice: return only what you need. Returning entire nodes when you only use one property wastes bandwidth and clutters results.

Quick Check

Test your RETURN knowledge.

Recap

You learned to shape query output with RETURN:

  • Return whole nodes or specific properties
  • Alias columns with AS
  • Use DISTINCT to remove duplicates
  • Include expressions and functions
  • Return paths and relationships when needed
免费开始

用 AI 导师学习 Neo4j Graph Database Fundamentals — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「使用 RETURN 返回并塑造结果」课时是免费的吗?

是的 — 「使用 RETURN 返回并塑造结果」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Neo4j Graph Database Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。

「使用 RETURN 返回并塑造结果」这节课中我会学到什么?

掌握 Cypher 的 RETURN 子句,对图查询的输出进行投影、设置别名和塑形。 你通过在浏览器中直接运行的动手代码来练习 Neo4j Graph Database Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Neo4j Graph Database Fundamentals 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Neo4j Graph Database Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「使用 RETURN 返回并塑造结果」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Neo4j Graph Database Fundamentals 课中编写并运行代码吗?

能。每节 Neo4j Graph Database Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 节点、关系与属性
  2. 使用 Cypher CREATE 创建数据
  3. 使用 Cypher MATCH 匹配模式
  4. 使用 RETURN 返回并塑造结果
← 返回 Neo4j Graph Database Fundamentals