I used the query:
MATCH (c:Customer)-[:PURCHASED]->(o:Order)-[:ORDERS]->(p:Product)
RETURN p.productID AS ProductID, p.productName AS ProductName, COUNT(*) AS NumberOfOrders
ORDER BY NumberOfOrders DESC
LIMIT 20
But the results from neo4j are wrong.
Can anyone help me to find the correct solution? (I will appreciate)
Also I should remove from the top N list of recommended items those items which ALFKI has purchased
I used the below sets of queries:
Query 1:
MATCH (c:Customer)-[:PURCHASED]->(o:Order)-[:ORDERS]->(p:Product) WHERE c.customerID="ALFKI"
DETACH DELETE p
RETURN*;
Query 2:
MATCH (c:Customer)-[:PURCHASED]->(o:Order)-[:ORDERS]->(p:Product)
RETURN p.productID AS ProductID, p.productName AS ProductName, COUNT(*) AS NumberOfOrders
ORDER BY NumberOfOrders DESC
LIMIT 23
But I would like to find and examine another one solution that used nested queries.
As for your second query, it sounds like you just need to exclude products that a particular customer has ordered. You don't need to, and almost always do not want to delete those orders from the graph. Using a <> operator will include all values not equal to the value in the where condition.
match (c:Customer)-[:PURCHASED]->(o:Order)-[orders:ORDERS]->(p:Product)
where c.customerID <> 'ALFKI'
return p.productID, p.productName, count(o.orderID) as num_orders
order by num_orders desc
limit 20
Please let me know if I'm misunderstanding something but these should help.
For details of the sample Northwinds database in the Neo4j browser type:
For first query my tutor said that his results are the correct ones. I spend some days without manage to retrieve the results he want. I did not get more help from him. Generally the all situation with him is a little bit straight.
For the second query we should remove from the list all the products that ALFKI purchased. With the above query we do not remove the items just remove ALFKI orders from count.
I really grateful for your help. I will wait for your further feedback.
Ah I see. So for the second query we want exclude all instances of items that ALFKI has ordered, regardless of which customer created the order / items? Would you like a query? One way off the top of my head to achieve this is to first match all orders -> items from ALFKI. Then using the COLLECT function you can store the itemIds in list. You can then use that list in the another match and exclude items included in that list. I can help write the query, however I wasn't sure if you wanted to give it a shot your self first.