Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-17-2020 04:52 AM
I have these relations:
NodeType1 A {ts:11} =r1=> NodeType2 m
NodeType1 B {ts: 22} =r1=> NodeType2 m
NodeType1 Y {ts: 22} =r1=> NodeType2 n
NodeType1 Z {ts: 32} =r1=> NodeType2 n
NodeType1 X {ts: 23} =r1=> NodeType2 o
.......
For each NodeType2, I wish to get max/min ts property NodeType1 who relate to it by r1
01-17-2020 05:47 AM
try use call and unwind,but not fit
01-17-2020 06:16 AM
[quote="naughtyGitCat, post:1, topic:13725"]
why not you write parameterized query?
Could u please let me know ts is property of node or relationship?
01-17-2020 06:19 AM
ts => timestamp
means NodeType1 node create time
01-17-2020 06:21 AM
How can your node Z has two 2 create time?
01-17-2020 06:22 AM
I'm sorry it's a mistake
NodeType1 A {ts:11} =r1=> NodeType2 m
NodeType1 B {ts: 22} =r1=> NodeType2 m
NodeType1 Y {ts: 22} =r1=> NodeType2 n
NodeType1 Z {ts: 32} =r1=> NodeType2 n
NodeType1 X {ts: 23} =r1=> NodeType2 o
01-17-2020 06:23 AM
I tried below
try below:
Load:
Merge(:NodeType1 {name:'A', ts:11}) -[:r1]-> (n1:NodeType2 {name:'m'});
Merge(:NodeType1 {name:'B', ts: 22}) -[:r1]-> (n1:NodeType2 {name:'m'});
merge(:NodeType1 {name:'Y', ts: 22}) -[:r1]-> (n1:NodeType2 {name:'n'});
merge(:NodeType1 {name:'Z', ts: 32}) -[:r1]-> (n1:NodeType2 {name:'n'});
merge(:NodeType1 {name:'X', ts: 23}) -[:r1]-> (n1:NodeType2 {name:'o'});
Merge Nodes:
MATCH (n1:NodeType2)
WITH n1.name
as name, collect(n1) as nodes
CALL apoc.refactor.mergeNodes(nodes, {properties: "combine"}) YIELD node
RETURN node
MATCH (n1:NodeType1)
WITH n1.name
as name, collect(n1) as nodes
CALL apoc.refactor.mergeNodes(nodes, {properties: "combine"}) YIELD node
RETURN node
01-17-2020 06:28 AM
Yeah,
for NodeType2 {
// run cypher to find max(ts) NodeType1;
}
is a method,
but need many times net io, and cause inconsistency
I mean do run cypher one time, to find group by type2 max(type1)
01-17-2020 06:31 AM
your code means
select max(type1) where type2.name='xxx'
No offense, but I want to do this way,
select max(type1) group by type2.name
01-17-2020 06:35 AM
I did not understand where did u get
select max(type1) where type2.name='xxx'
In my query as below, with n2 means you group by n2 node given in the match
match (n1:NodeType1 ) -[r1]-> (n2:NodeType2 {name:'m'})
with n2, max(n1.ts) as maxval, min(n1.ts) as minval
return n2, maxval,minval
01-17-2020 06:38 AM
yes, but the NodeType2 name is not specified at first, in database, there is a lot of NodeType2 node but not all named by m
01-17-2020 06:41 AM
As I mentioned us parameterized query. You can pass any value in parameter for an example i passed m
:param node2:'m'
match (n1:NodeType1 ) -[r1]-> (n2:NodeType2 {name:$node2)
with n2, max(n1.ts) as maxval, min(n1.ts) as minval
return n2, maxval,minval
01-18-2020 05:49 AM
Yes。We can send many times parameterized query to neo4j server, But this need many times net io, and cause inconsistency, unless do a explict trx.begin(), Is there any way to send a non parameterized query to finish it
01-18-2020 06:06 AM
Try match (n1:NodeType1 ) -[r1]-> (n2:NodeType2)
with n2, max(n1.ts) as maxval, min(n1.ts) as minval
return n2, maxval,minval
01-17-2020 06:20 AM
why not you write parameterized query?
you mean do forloop or foreach in program logic?
01-17-2020 05:56 AM
Your question's title is fairly misleading:
The language you're using is called cypher. I suspect your asking for aggregation functions, see https://neo4j.com/docs/cypher-manual/current/functions/aggregating/
01-17-2020 06:09 AM
cypher query language => CQL?
GROUP BY is a calc method, dont care about the name
01-17-2020 06:11 AM
and agggregate only run on a specific node,but not unknown nodes
05-27-2020 11:11 AM
I understood what he meant, I have the same question.
I've blown a "merge" statement, so now I have too many nodes (with a specific label) to "DETACH DELETE" in one transaction. So I want to do an operation that in SQL I would accomplish with a "GROUP BY" -- I want to somehow match a group of nodes based on an attribute, "DETACH DELETE" each of those (in a single transaction), then iterate until all the nodes are gone.
I'm new to Cypher, and so I'm still struggling to understand the semantics of these group operators.
On a related note, is there any way to perform multiple transactions (inside a subquery or something) from the neobrowser (the tool that comes up on port 7474)?
05-20-2022 12:36 AM
MATCH (n:Label {key:value}) <- This match a group of nodes based on an attribute and a label
RETURN n
All the sessions of the conference are now available online