集計とプロジェクション
集計関数(例:COUNT、SUM)の使い方と、分析用にデータをカスタム形式へプロジェクションする方法を学びます。
「集計とプロジェクション」はCoddyKit上の無料Neo4j Graph Database Fundamentalsレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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.ageCustomizing 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 YearReleasedCounting 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 TotalPeopleCountCounting 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 UniqueAgesCountSumming 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 AverageAgeFinding 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 OldestPersonAgeGrouping 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 AllPersonNamesStructuring 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 PersonSummaryQuick 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
RETURNallow you to select specific data, rename it withAS, or create structured maps. - Aggregation functions like
COUNT(),SUM(),AVG(),MIN(),MAX(), andCOLLECT()help you analyze and summarize large datasets into meaningful insights.
These techniques are fundamental for extracting valuable information from your Neo4j graphs!
よくある質問
「集計とプロジェクション」レッスンは無料ですか?
はい。「集計とプロジェクション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Neo4j Graph Database Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Neo4j Graph Database Fundamentalsコースには全4レッスンが含まれています。
「集計とプロジェクション」で何を学びますか?
集計関数(例:COUNT、SUM)の使い方と、分析用にデータをカスタム形式へプロジェクションする方法を学びます。 ブラウザで直接実行するハンズオンコードでNeo4j Graph Database Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Neo4j Graph Database Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNeo4j Graph Database Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「集計とプロジェクション」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNeo4j Graph Database Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのNeo4j Graph Database Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。