Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-29-2021 06:37 AM
I have to find the results of top N items base on purchase orders for Orders of Northwind dataset.
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.
Solved! Go to Solution.
05-31-2021 10:27 AM
05-29-2021 03:40 PM
Hi,
Would you mind posting the results you are expecting as well as the results you are getting?
Thanks,
-Matt
05-29-2021 04:25 PM
Hi Matt
I would like to thank you for your response.
Wrong results:
Expecting results:
Also I would like to ask you if you can fins an alternative solution for the below queries:
05-29-2021 04:26 PM
05-29-2021 06:34 PM
Hi chragr19,
So your query and results look correct. You can double check the values used in the sample Northwinds database here:
http://data.neo4j.com/northwind/order-details.csv
http://data.neo4j.com/northwind/products.csv
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:
:play Northwinds
Thanks!!
-Matt
05-30-2021 02:11 AM
Matt,
Thank you for your support.
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.
Thank you,
Christodoulos
05-30-2021 02:07 PM
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.
Thanks !
-matt
05-31-2021 10:11 AM
Matt,
I follow your advice and manage to find another solution by using the COLLECT clause!!
Thank you for your support and help. I am glad to meet such people, who still help each other.
Your are the best!!
CA
05-31-2021 10:27 AM
No problem, glad it worked!
All the sessions of the conference are now available online