Neo4j Graph Database Fundamentals · บทเรียน

การรวมข้อมูลและการฉายข้อมูล

ค้นพบวิธีใช้ฟังก์ชันการรวมข้อมูล (เช่น COUNT, SUM) และฉายข้อมูลให้อยู่ในรูปแบบกำหนดเองเพื่อการวิเคราะห์

บทเรียน 2 จาก 411 ขั้นตอน

การรวมข้อมูลและการฉายข้อมูล เป็นบทเรียน Neo4j Graph Database Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Neo4j Graph Database Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Neo4j Graph Database Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Analyze Your Graph Data

Welcome to Aggregation and Projections! In graph databases, you often need to do more than just find data; you need to summarize it or shape it for analysis.

Aggregation means calculating a single result from multiple items, like counting all nodes or finding the average age. Projection is about selecting and formatting the data you want to see in your results.

Selecting Data with RETURN

The RETURN clause is how you specify exactly what data you want to see from your query. You can return nodes, relationships, or their specific properties. Let's add some example data first, then try a basic projection.

CREATE (p1:Person {name: 'Alice', age: 30})
CREATE (p2:Person {name: 'Bob', age: 25})
CREATE (p3:Person {name: 'Charlie', age: 30})
CREATE (m1:Movie {title: 'Inception', releaseYear: 2010})
CREATE (m2:Movie {title: 'Dunkirk', releaseYear: 2017})
CREATE (m3:Movie {title: 'Interstellar', releaseYear: 2014})

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

Customizing Output with AS

The default property names might not always be clear in your results. The AS keyword lets you rename returned items to make your query output more readable and descriptive. This is part of projection.

MATCH (m:Movie)
RETURN m.title AS FilmTitle, m.releaseYear AS YearReleased

Counting All Items with COUNT(*)

Aggregation functions help you summarize data. One of the most common is COUNT(*), which tells you the total number of items (nodes, relationships, or paths) found by your MATCH pattern.

MATCH (p:Person)
RETURN COUNT(*) AS TotalPeopleCount

Counting Unique Values

What if you only want to count the unique values for a specific property? Use COUNT(DISTINCT variable.property). This is great for finding how many different ages, titles, or categories exist in your graph.

MATCH (p:Person)
RETURN COUNT(DISTINCT p.age) AS UniqueAgesCount

Summing and Averaging Numbers

For numeric properties, you can calculate sums and averages. SUM() adds up all values, and AVG() computes their mean. These functions are very powerful for numerical analysis.

MATCH (p:Person)
RETURN SUM(p.age) AS TotalAgeSum, AVG(p.age) AS AverageAge

Finding Extremes with MIN/MAX

The MIN() and MAX() functions let you find the smallest and largest values for a property within your matched data. This is useful for identifying outliers or understanding data ranges.

MATCH (p:Person)
RETURN MIN(p.age) AS YoungestPersonAge, MAX(p.age) AS OldestPersonAge

Grouping into Lists with COLLECT

The COLLECT() function gathers all values of a specified property into a list. This is often used with grouping (which we'll cover later) but can also simply return all collected items in a list.

MATCH (p:Person)
RETURN COLLECT(p.name) AS AllPersonNames

Structuring Results with Maps

You can project complex, structured data using map projections. This allows you to create custom objects (maps) in your results, combining multiple properties and even calculated values into a single output column.

MATCH (p:Person)
RETURN {fullName: p.name, yearsOld: p.age, isAdult: p.age >= 18} AS PersonSummary

Quick Aggregation & Projection Check

Let's test your understanding of Cypher aggregation and projection. Choose all statements that correctly apply these concepts.

Recap: Aggregating & Projecting

Great job! You've learned how to summarize and shape your graph data using Cypher.

  • Projections with RETURN allow you to select specific data, rename it with AS, or create structured maps.
  • Aggregation functions like COUNT(), SUM(), AVG(), MIN(), MAX(), and COLLECT() help you analyze and summarize large datasets into meaningful insights.

These techniques are fundamental for extracting valuable information from your Neo4j graphs!

เริ่มต้นได้ฟรี

เรียนรู้ Neo4j Graph Database Fundamentals ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การรวมข้อมูลและการฉายข้อมูล” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การรวมข้อมูลและการฉายข้อมูล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Neo4j Graph Database Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Neo4j Graph Database Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การรวมข้อมูลและการฉายข้อมูล”

ค้นพบวิธีใช้ฟังก์ชันการรวมข้อมูล (เช่น COUNT, SUM) และฉายข้อมูลให้อยู่ในรูปแบบกำหนดเองเพื่อการวิเคราะห์ คุณปฏิบัติ Neo4j Graph Database Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Neo4j Graph Database Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Neo4j Graph Database Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การรวมข้อมูลและการฉายข้อมูล” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Neo4j Graph Database Fundamentals นี้ได้ไหม

ได้ บทเรียน Neo4j Graph Database Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การกรองและจัดเรียงผลลัพธ์
  2. การรวมข้อมูลและการฉายข้อมูล
  3. การอัปเดตและลบข้อมูลกราฟ
  4. การรวมคำค้นด้วย WITH และ UNION
← กลับไปที่ Neo4j Graph Database Fundamentals