cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to find intersections

**Consider hotels in pune. Some hotels provide lodging facilities whereas some provide only restaurant facilities and some provide both.

Query is List the names of hotels having both lodging and restaurant facility

1 ACCEPTED SOLUTION

your cypher of

MATCH (c:Country)-[:Has]->(s:State),
              (p:Product)-[r:produced_across]->(s:State)
 where r.pper>r.cper return c.name,p.name

is going to do the following

  1. match (c:Country)-[:Has]->(s:State) will identify every path from a :Country node to a :State node. this for example might result on 150 paths.
  2. (p:Product)-[r:produced_across]->(s:State) will identify every path from a :Product to a :State
    node, this file example might result in 1000 paths.
  3. We will then cartersian join the 150 paths from the 1st statement against the 1000 paths of the 2nd.
  4. and then we apply the where clause against the result of the cartesian.

I dont suspect you want step #3 above, though maybe I'm wrong.

Back to your original provided

match(p:Product),(s:State) 
where p.name="Sugarcane" and s.name="Berlin" 
create(p)-[:produced_across{pper:72,cper:50}]->(s) return p,s

i think your query should simply be

MATCH  (p:Product)-[r:produced_across]->(s:State)-[:Has]-(c:Country)
 where r.pper>r.cper return c.name,p.name

View solution in original post

11 REPLIES 11

Hello,

More info on your graph model would help people to provide you with an answer.

My guess here would be something like :

MATCH (:Facility{type:"Lodging"})--(n:Hotel)--(:Facility{type:"Restaurant"})
RETURN n

But I could be completely wrong depending on your model.

fired above query but returned no rows. so kindly help me to find answer

node and relationships are like following
create (h:Hotel{name:"New Poona Cafe",address:"Camp"}) return h
create (h:Hotel{name:"Modern Cafe",address:"Camp"}) return h
create(f:Facility{name:"Lodging"}) return f
create(f:Facility{name:"Restaurant"}) return f
match(h:Hotel),(f:Facility) where h.name="New Poona Cafe" and f.name="Lodging"create (h)-[:provides]->(f) return h,f
match(h:Hotel),(f:Facility) where h.name="New Poona Cafe" and f.name="Restaurant"create (h)-[:provides]->(f) return h,f
match(h:Hotel),(f:Facility) where h.name="Modern Cafe" and f.name="Restaurant"create (h)-[:provides]->(f) return h,f
answer could be: New Poona Cafe

Thanks a lot now the query is working very fine I am so thankful to you

Kindly help me to find answer of following query

List the countries that do not import and export any product

The database is as follows:
Products are produced across different states in a country . Production of the products is measured in %.A product can be exported if its production exceeds 60%. A product needs to be imported if its consumption percentage is more than its production percentage in a country.
State node and country node are related with has relationship then state produces prodct. the relationship is as follows
match(p:Product),(s:State) where p.name="Sugarcane" and s.name="Berlin" create(p)-[:produced_across{pper:72,cper:50}]->(s) return p,s
Kindly help me to solve above query

2 issues

  1. the last update regarding help for writing a query based upon countries and import/export appears to be different then the original problem description of 'How to find intersections'. Ideally each issue should be its own question and not one long never ending question.

  2. you provide details of the relationship and thus

match(p:Product),(s:State) where p.name="Sugarcane" and s.name="Berlin" create(p)-[:produced_across{pper:72,cper:50}]->(s) return p,s

what does 'pper' and 'cper' represent. If I read the above it appears to be create a realtionshop from the Product node which has a name of 'Sugarcane' and the State node which has a name of 'Berlin' and set attributes on the relationship of pper and cper but there is no detail what these paraemters represent

What have you tried so far with reference to solving your query concern?

pper is the production percentage and cper is the consumption percentage taken while creating relationship.

do you have a base query that gets you for example 90% of the answer.

hello,
I have tried following query, Kindly check and help me out
MATCH (c:Country)-[:Has]->(s:State),(p:Product)-[r:produced_across]->(s:State) where r.pper>r.cper return c.name,p.name

your cypher of

MATCH (c:Country)-[:Has]->(s:State),
              (p:Product)-[r:produced_across]->(s:State)
 where r.pper>r.cper return c.name,p.name

is going to do the following

  1. match (c:Country)-[:Has]->(s:State) will identify every path from a :Country node to a :State node. this for example might result on 150 paths.
  2. (p:Product)-[r:produced_across]->(s:State) will identify every path from a :Product to a :State
    node, this file example might result in 1000 paths.
  3. We will then cartersian join the 150 paths from the 1st statement against the 1000 paths of the 2nd.
  4. and then we apply the where clause against the result of the cartesian.

I dont suspect you want step #3 above, though maybe I'm wrong.

Back to your original provided

match(p:Product),(s:State) 
where p.name="Sugarcane" and s.name="Berlin" 
create(p)-[:produced_across{pper:72,cper:50}]->(s) return p,s

i think your query should simply be

MATCH  (p:Product)-[r:produced_across]->(s:State)-[:Has]-(c:Country)
 where r.pper>r.cper return c.name,p.name

Thanks a lot for the answer