Testes no SandBox do Neo4J
MATCH (n) DETACH DELETE n;
CREATE (c1:Country { name: 'Germany', language: 'German', continent: 'Europe', population: 83000000 });
CREATE (c2:Country { name: 'France', language: 'French', continent: 'Europe', population: 67000000 });
CREATE (c3:Country { name: 'United Kingdom', language: 'English', continent: 'Europe', population: 66000000 });
MATCH (c1),(c2)
WHERE c1.name= 'Germany' AND c2.name = 'France'
CREATE (c2)<-[:WORKING_IN { date_of_start: 2014 }]-(p:Person { name: 'John' })-[:LIVING_IN { date_of_start: 2014 }]->(c1);
MATCH (c)
WHERE c.name= 'United Kingdom'
CREATE (c)<-[:WORKING_IN { date_of_start: 2014 }]-(p:Person { name: 'Harry' })-[:LIVING_IN { date_of_start: 2013 }]->(c);
MATCH (p1),(p2)
WHERE p1.name = 'John' AND p2.name = 'Harry'
CREATE (p1)-[:FRIENDS_WITH { date_of_start: 2011 }]->(p2);
MATCH (p1),(p2)
WHERE p1.name = 'John' AND p2.name = 'Harry'
CREATE (p1)<-[:FRIENDS_WITH { date_of_start: 2012 }]-(:Person { name: 'Anna' })-[:FRIENDS_WITH { date_of_start: 2014 }]->(p2);
MATCH (p),(c1),(c2)
WHERE p.name = 'Anna' AND c1.name = 'United Kingdom' AND c2.name = 'Germany'
CREATE (c2)<-[:LIVING_IN { date_of_start: 2016 }]-(p)-[:LIVING_IN { date_of_start: 2014 }]->(c1);
--
MATCH (n)-[r]->(m) RETURN n,r,m;
--
MATCH (:Country {name: 'United Kingdom'})-[r]-(p)
WHERE r.date_of_start = 2014
RETURN p;
--
MATCH (n:Person)-[k:FRIENDS_WITH]-(f)
WHERE k.date_of_start > 2010
RETURN n.name, f.name, k.date_of_start AS since
--
MATCH (n:Person)-[k1:FRIENDS_WITH]->(f1)
MATCH (n:Person)-[k2:FRIENDS_WITH]->(f2)
WHERE k2.date_of_start > k1.date_of_start
RETURN n.name, f2.name, k2.date_of_start AS since
--
MATCH (n1:Person)-[k1:FRIENDS_WITH]->(n3:Person)
MATCH (n2:Person)-[k2:FRIENDS_WITH]->(n4:Person)
WHERE k2.date_of_start = k1.date_of_start and n1 <> n2
RETURN n1.name, n3.name, n2.name, n4.name, k2.date_of_start AS since
--
MATCH (n1:Person)-[l1:LIVING_IN]->(c1:Country)
MATCH (n2:Person)-[l2:LIVING_IN]->(c2:Country)
WHERE l1.date_of_start = l2.date_of_start and n1 <> n2
RETURN n1.name, c1.name, n2.name, c2.name, l2.date_of_start AS since
--
WITH 2010 AS since
MATCH rels= (p1:Person) - [:FRIENDS_WITH*1..2]->(p2:Person)
WHERE ALL(k1 in relationships(rels) WHERE k1.date_of_start > since)
RETURN rels;
Documentação
OpenCypher
OPTIONAL MATCH, specify the patterns to search for in the database while using nulls for missing parts of the pattern.
WHERE, for filtering the matched data;
RETURN, for defining what will be presented to the user in the result set;
WHERE
is part of the directly preceding MATCH or OPTIONAL MATCH clause and
should always be used like that to avoid problems with performance or
results.
WHERE adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause.
WHERE EXISTS { ... } an existential sub-query used to filter the results of a MATCH, OPTIONAL MATCH or WITH clause.
Neo4j will just traverse all relationships and read the
property value. There are by default no indexes on relationships
properties (this can be achieved with the legacy indexes : check
documentation).
RETURN ... [AS] projecting clauses: these comprise clauses that define which expressions to return in the result set. The returned expressions may all be aliased using AS.
Comentários
Postar um comentário
Sinta-se a vontade para comentar. Críticas construtivas são sempre bem vindas.