結果のフィルタリングと並べ替え
WHERE句とORDER BY句を使ってクエリ結果を絞り込み、必要なデータだけを正確に取得します。
「結果のフィルタリングと並べ替え」はCoddyKit上の無料Neo4j Graph Database Fundamentalsレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNeo4j Graph Database Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Neo4j Graph Database Fundamentalsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Refine Your Graph Queries
When working with large graphs, you often need to find very specific information or present it in a particular order.
- Filtering helps you narrow down results to only what's relevant.
- Ordering helps you sort your results for better readability or analysis.
In this lesson, we'll master the WHERE and ORDER BY clauses in Cypher.
Filter Results with WHERE
The WHERE clause is used to filter patterns or properties based on specific conditions. It typically comes after a MATCH clause.
Think of it like saying: "Find me all people, WHERE their birth year is 1970."
MATCH (p:Person)
WHERE p.born = 1970
RETURN p.name AS Name, p.born AS BornYearComparison Operators
You can use various comparison operators in your WHERE clause:
=(equal to)<>(not equal to)>(greater than)<(less than)>=(greater than or equal to)<=(less than or equal to)
Let's find movies released after the year 2000.
MATCH (m:Movie)
WHERE m.released > 2000
RETURN m.title AS MovieTitle, m.released AS ReleaseYearLogical Operators (AND, OR)
Combine multiple conditions using logical operators:
AND: Both conditions must be true.OR: At least one condition must be true.XOR: Exactly one condition must be true.NOT: Negates a condition.
Find people born between 1970 and 1980 (inclusive).
MATCH (p:Person)
WHERE p.born >= 1970 AND p.born <= 1980
RETURN p.name AS Name, p.born AS BornYearString and List Operators
Cypher offers powerful operators for string matching and list containment:
CONTAINS,STARTS WITH,ENDS WITHfor partial string matches.INto check if a property value is within a list of values.
Let's find specific actors by name using IN.
MATCH (p:Person)
WHERE p.name IN ['Tom Hanks', 'Keanu Reeves', 'Carrie-Anne Moss']
RETURN p.name AS ActorNameSort Your Results with ORDER BY
The ORDER BY clause sorts your query results. It comes after RETURN (or WITH).
By default, results are sorted in ascending order (smallest to largest, A-Z).
MATCH (p:Person)
RETURN p.name AS ActorName
ORDER BY ActorNameAscending & Descending Order
You can explicitly specify the sort direction:
ASC: Ascending (A-Z, 0-9). This is the default.DESC: Descending (Z-A, 9-0).
Let's sort movies by their release year, from newest to oldest.
MATCH (m:Movie)
RETURN m.title AS MovieTitle, m.released AS ReleaseYear
ORDER BY ReleaseYear DESCMulti-Level Sorting
You can sort by multiple properties. The order in which you list them in ORDER BY matters.
Cypher will first sort by the first property, then by the second for any ties in the first, and so on.
Sort people by birth year (ascending), and then by name (ascending) for those born in the same year.
MATCH (p:Person)
RETURN p.born AS BornYear, p.name AS ActorName
ORDER BY BornYear ASC, ActorName ASCPutting it All Together
A typical Cypher query flow often involves:
MATCH: Find the graph pattern.WHERE: Filter the matched patterns.RETURN: Select the data you want.ORDER BY: Sort the returned data.
Find actors born before 1970, order them by name (descending), then by the movie title they acted in (ascending).
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.born < 1970
RETURN p.name AS Actor, m.title AS Movie, p.born AS BornYear
ORDER BY Actor DESC, Movie ASCFilter & Order Challenge
Which Cypher query correctly finds movies released after 1999 and orders them by title in descending order?
Recap: Refined Queries
Great job! You've learned how to precisely control your Cypher query results:
- The
WHEREclause filters data based on conditions. - The
ORDER BYclause sorts your results in ascending or descending order. - You can combine these with comparison, logical, and string/list operators for powerful filtering.
Next, we'll explore how to summarize and reshape your data with Aggregation and Projections!
よくある質問
「結果のフィルタリングと並べ替え」レッスンは無料ですか?
はい。「結果のフィルタリングと並べ替え」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Neo4j Graph Database Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Neo4j Graph Database Fundamentalsコースには全4レッスンが含まれています。
「結果のフィルタリングと並べ替え」で何を学びますか?
WHERE句とORDER BY句を使ってクエリ結果を絞り込み、必要なデータだけを正確に取得します。 ブラウザで直接実行するハンズオンコードでNeo4j Graph Database Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Neo4j Graph Database Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNeo4j Graph Database Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「結果のフィルタリングと並べ替え」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNeo4j Graph Database Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのNeo4j Graph Database Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 結果のフィルタリングと並べ替え
- 集計とプロジェクション
- グラフデータの更新と削除
- WITHとUNIONによるクエリの結合