Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-08-2020 05:51 PM
Hello everyone, I am a novice, and I have a question about time attributes.
If the relationship between the nodes changes over time, such as the equity relationship, after a period of time, shareholders will sell their stocks or buy new stocks. How can this time attribute be reflected in neo4j.
11-09-2020 01:25 PM
Hi @220191539
How about this one.
One of the examples has put a buy and sell in a relationship.
The other has been made into the Stock nodes.
CREATE (:Person {name: "I"})-[:HAS_STOCK {buy:"2020-11-06T20:07:28.768000000Z"}]->(company:Company {name:"Company1"}),
(:Person {name: "You"})-[:HAS_STOCK {buy: "2020-09-20T20:07:28.768000000Z", sell: "2020-11-10T20:07:28.768000000Z"}]->(company)
CREATE (:Person {name: "Him"})-[:HAS_STOCK]->(:Stock {buy:"2020-11-06T20:07:28.768000000Z"})-[:COMPANY]->(company2:Company {name:"Company2"}),
(:Person {name: "Her"})-[:HAS_STOCK]->(:Stock {buy: "2020-09-20T20:07:28.768000000Z", sell: "2020-11-10T20:07:28.768000000Z"})-[:COMPANY]->(company2);
11-09-2020 04:48 PM
Here is my solution:
MERGE (calldate:CallDate {date:"20-11-06"})
MERGE (p:Person {name: "I"})
MERGE (calldate)-[:PERSON]->(p)
MERGE (calltime:Connect {time: "20:07:28"})
MERGE (b:BuyStock {amount: 100})
MERGE (c:Company {name: "XYZ"})
MERGE (p)-[:CALL_TIME]->(calltime)
MERGE (calltime)-[:BUY_STOCK]->(b)
MERGE (b)-[:COMPANY]->(c)
MERGE (calltime1:Connect {time: "20:27:28"})
MERGE (b1:BuyStock {amount: 200})
MERGE (c1:Company {name: "XYZ1"})
MERGE (p)-[:CALL_TIME]->(calltime1)
MERGE (calltime1)-[:BUY_STOCK]->(b1)
MERGE (b1)-[:COMPANY]->(c1)
MERGE (calltime2:Connect {time: "18:07:28"})
MERGE (s:SellStock {amount: 400})
//MERGE (c2:Company {name: "XYZ2"})
MERGE (p)-[:CALL_TIME]->(calltime2)
MERGE (calltime2)-[:SELL_STOCK]->(s)
MERGE (s)-[:COMPANY]->(c1)
Result:
11-10-2020 05:14 PM
Thanks for your answer, I still have some questions.
If many companies are trading at this time, this node will be connected by many companies. How to name this node?
11-11-2020 09:10 PM
Hi @220191539
My answer was simply to indicate whether it was a relationship or a node.
I think @ameyasoft answer is better.
I wrote another Cypher that mimics his method.
The names of the nodes are (:BuyStock) and (:SellStock).
Does that answer your question?
// Company
MERGE (c:Company {name: 'XYZ'})
MERGE (c1:Company {name: 'XYZ1'})
// Person
MERGE (p:Person {name: 'I'})
// Date
MERGE (year:Year {year: 2020})-[:MONTH]->(:Month {month: 11})-[:DAY]->(day:Day {month: 6})
// Buy Stock 1
MERGE (b1:BuyStock {amount: 100, time: '20:07:28'})
MERGE (b1)-[:COMPANY]->(c)
MERGE (p)-[:BUY_STOCK]->(b1)
MERGE (day)-[:DAY]->(b1)
// Buy Stock 2
MERGE (b2:BuyStock {amount: 200, time: '20:07:28'})
MERGE (b2)-[:COMPANY]->(c1)
MERGE (p)-[:BUY_STOCK]->(b2)
MERGE (day)-[:DAY]->(b2)
// Sell Stock 1
MERGE (s1:SellStock {amount: 400, time: '20:07:28'})
MERGE (s1)-[:COMPANY]->(c1)
MERGE (p)-[:SELL_STOCK]->(s1)
MERGE (day)-[:DAY]->(s1);
All the sessions of the conference are now available online