Medium Example
Setup
Import
Medium Example
Setup
Import
MATCH (p1:Person)-[:OUT]->(c:Call) | |
WHERE p1.name = "Robert" | |
RETURN p1.name as name, count(c) as total_calls, max(c.duration) as max_duration |
// Dijkstra | |
MATCH (p1:Person { name:'Omar' }), (p2:Person { name:'Ronin' }) | |
CALL algo.shortestPath.stream(p1, p2, 'duration') YIELD nodeId, cost | |
RETURN algo.asNode(nodeId).name AS name, cost | |
// Dijkstra Projection | |
MATCH (p1:Person { name: 'Omar' }), (p2:Person { name: 'Ronin' }) | |
CALL algo.shortestPath(p1, p2, 'cost',{ | |
nodeQuery:'MATCH (p:Person) RETURN id(p) as id', | |
relationshipQuery:'MATCH (p1:Person)-[c:COMMUNICATE_WITH]->(p2:Person) RETURN id(p1) as source, id(p2) as target, c.duration as weight', |
// How to works with Date Type here: | |
// https://neo4j.com/docs/cypher-manual/current/syntax/temporal/#cypher-temporal-accessing-components-temporal-instants | |
MATCH (p:Person)-[]->(c:Call) | |
WITH p.number as num, p.name as name, sum(c.duration) as d | |
WHERE name STARTS WITH "A" | |
RETURN num, name, d | |
ORDER BY d DESC | |
LIMIT 10 |
MATCH (c1:Call { duration: 10 })<-[:IN]-(p:Person) | |
WHERE (p)-[:OUT]->(:Call { duration: 5 }) AND c1.from.month = 7 | |
RETURN p |
// Check the data | |
MATCH (p1:Person)-[:OUT]->(c:Call)<-[]-(p2:Person) | |
WHERE c.duration > 0 | |
RETURN p1.name, p2.name, sum(c.duration) as duration, count(c) as calls | |
ORDER BY duration DESC | |
LIMIT 10 | |
// Check one pair | |
MATCH (p1:Person { name: "Kara" })-[*2]-(p2:Person { name: "Hailee" }) | |
RETURN p1, p2 |
// How to use DISTINCT https://neo4j.com/docs/cypher-manual/current/clauses/return/#return-unique-results | |
MATCH (:City { name: "Bangkok" })<-[:FROM]-(p1:Person { gender: "Man" }) | |
MATCH (p1)-[:OUT]->(:Call)<-[:IN]-(p2:Person { gender: "Woman" })-[:FROM]->(:City { name: "Pattaya" }) | |
RETURN p1.name as fromBangkok, p2.name as toPattaya |
// How to use NOT: https://neo4j.com/docs/cypher-manual/current/clauses/where/#filter-on-patterns-using-not | |
MATCH (c:Call) | |
WHERE c.from.month = 2 | |
RETURN date(c.from), count(c) as calls | |
ORDER BY calls | |
LIMIT 10 |
MATCH (p1:Person)-[:OUT]->(:Call)<-[:IN]-(p2:Person) | |
WHERE p1.name = "Robert" | |
RETURN p2 |
MATCH (c:Call) | |
WHERE c.from.month = 5 | |
RETURN count(c) as calls |