Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modeling Cypher Exercise 1 and 2
MATCH (company)<-[:WORKS_FOR]-(me:Person{username:'ian'})-[:HAS_SKILL]->(skill),
(company)<-[:WORKS_FOR]-(colleague)-[r:HAS_SKILL]->(skill)
WHERE r.level > 1
RETURN colleague.username AS username,
count(skill) AS score,
collect(skill.name) AS skills
ORDER BY score DESC
CREATE
(ben:Person{username:'ben'}),
(charlie:Person{username:'charlie'}),
(lucy:Person{username:'lucy'}),
(ian:Person{username:'ian'}),
(sarah:Person{username:'sarah'}),
(emily:Person{username:'emily'}),
(gordon:Person{username:'gordon'}),
(kate:Person{username:'kate'}),
(acme:Company{name:'Acme, Inc'}),
(startup:Company{name:'Startup, Ltd'}),
(neo4j:Skill{name:'Neo4j'}),
(rest:Skill{name:'REST'}),
(dotNet:Skill{name:'DotNet'}),
(ruby:Skill{name:'Ruby'}),
(sql:Skill{name:'SQL'}),
(architecture:Skill{name:'Architecture'}),
(java:Skill{name:'Java'}),
(python:Skill{name:'Python'}),
(javascript:Skill{name:'Javascript'}),
(clojure:Skill{name:'Clojure'}),
(ben)-[:WORKS_FOR]->(acme),
(charlie)-[:WORKS_FOR]->(acme),
(lucy)-[:WORKS_FOR]->(acme),
(ian)-[:WORKS_FOR]->(acme),
(sarah)-[:WORKS_FOR]->(startup),
(emily)-[:WORKS_FOR]->(startup),
(gordon)-[:WORKS_FOR]->(startup),
(kate)-[:WORKS_FOR]->(startup),
(ben)-[:HAS_SKILL{level:1}]->(neo4j),
(ben)-[:HAS_SKILL{level:3}]->(rest),
(charlie)-[:HAS_SKILL{level:2}]->(neo4j),
(charlie)-[:HAS_SKILL{level:1}]->(javascript),
(charlie)-[:HAS_SKILL{level:1}]->(sql),
(lucy)-[:HAS_SKILL{level:3}]->(dotNet),
(lucy)-[:HAS_SKILL{level:2}]->(architecture),
(lucy)-[:HAS_SKILL{level:1}]->(python),
(ian)-[:HAS_SKILL{level:2}]->(java),
(ian)-[:HAS_SKILL{level:3}]->(neo4j),
(ian)-[:HAS_SKILL{level:2}]->(rest),
(sarah)-[:HAS_SKILL{level:1}]->(neo4j),
(sarah)-[:HAS_SKILL{level:1}]->(java),
(sarah)-[:HAS_SKILL{level:1}]->(rest),
(sarah)-[:HAS_SKILL{level:1}]->(clojure),
(emily)-[:HAS_SKILL{level:1}]->(neo4j),
(emily)-[:HAS_SKILL{level:1}]->(dotNet),
(emily)-[:HAS_SKILL{level:1}]->(python),
(gordon)-[:HAS_SKILL{level:1}]->(dotNet),
(gordon)-[:HAS_SKILL{level:1}]->(ruby),
(kate)-[:HAS_SKILL{level:1}]->(architecture),
(kate)-[:HAS_SKILL{level:1}]->(python)
CREATE
(ben:Person{username:'ben'}),
(acme:Company{name:'Acme, Inc'}),
(neo4j:Skill{name:'Neo4j'}),
(rest:Skill{name:'REST'}),
(ben)-[:WORKS_FOR]->(acme),
(ben)-[:HAS_SKILL{level:1}]->(neo4j),
(ben)-[:HAS_SKILL{level:3}]->(rest)
MERGE (c:Company{name:'Acme, Inc'})
MERGE (p:Person{username:'ian'})
MERGE (s1:Skill{name:'Java'})
MERGE (s2:Skill{name:'C#'})
MERGE (s3:Skill{name:'Neo4j'})
MERGE (c)<-[:WORKS_FOR]-(p)
MERGE (p)-[r1:HAS_SKILL]->(s1)
MERGE (p)-[r2:HAS_SKILL]->(s2)
MERGE (p)-[r3:HAS_SKILL]->(s3)
SET r1.level = 2
SET r2.level = 2
SET r3.level = 3
RETURN c, p, s1, s2, s3
MERGE (c:Company{name:'Acme, Inc'})
MERGE (p:Person{username:'lucy'})
MERGE (s1:Skill{name:'Java'})
MERGE (s2:Skill{name:'Neo4j'})
MERGE (c)<-[:WORKS_FOR]-(p)
MERGE (p)-[r1:HAS_SKILL]->(s1)
MERGE (p)-[r2:HAS_SKILL]->(s2)
SET r1.level = 3
SET r2.level = 2
RETURN c, p, s1, s2
MERGE (c:Company{name:'Acme, Inc'})
MERGE (p:Person{username:'bill'})
MERGE (s1:Skill{name:'Neo4j'})
MERGE (s2:Skill{name:'Ruby'})
MERGE (c)<-[:WORKS_FOR]-(p)
MERGE (p)-[r1:HAS_SKILL]->(s1)
MERGE (p)-[r2:HAS_SKILL]->(s2)
SET r1.level = 1
SET r2.level = 2
RETURN c, p, s1, s2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.