Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-28-2020 12:45 PM
I have this query:
MATCH (n)
WHERE
ID(n) = 770892
OPTIONAL MATCH (n)-[s:TAGGED_TOGETHER]-(d)
WHERE
s.tagged_together >= 0 AND
((d.timestamp>'2018/01/01' AND d.timestamp<'2019/01/01') OR
(d.removed_timestamp>'2018/01/01' AND d.removed_timestamp<'2019/01/01')) AND
d.nodeDegree>=0
RETURN n AS node, d AS tagged, size((n)-[s]-()) AS counter
I want to return how many tagged_together relationships there are for the selected node n,
but in this way the output for the column counter
is always 1 for each row
although it has more of one relationship . Is there a way to return the total counter of all the relatioship or to sum each value in the column ?
Solved! Go to Solution.
04-29-2020 01:23 AM
The data are saved in my db in this way:
Friend
nodes there is a relationship between this node and a node user
Friend
there is a relathionship tagged_together
At the end I have result in this way grouping by n:
MATCH (n )
WHERE
ID(n) = 770903
OPTIONAL MATCH (n)-[s:TAGGED_TOGETHER]-(d)
WHERE
s.tagged_together >= 0 AND
((d.timestamp>'2016/01/01' AND d.timestamp<'2019/01/01') OR
(d.removed_timestamp>'2016/01/01' AND d.removed_timestamp<'2019/01/01')) AND
d.nodeDegree>=0
RETURN n , collect(d.name) , count(s)
04-28-2020 12:53 PM
Hi @lx2pwnd
Please try
MATCH (n)
WHERE
ID(n) = 770892
OPTIONAL MATCH (n)-[s:TAGGED_TOGETHER]-(d)
WHERE
s.tagged_together >= 0 AND
((d.timestamp>'2018/01/01' AND d.timestamp<'2019/01/01') OR
(d.removed_timestamp>'2018/01/01' AND d.removed_timestamp<'2019/01/01')) AND
d.nodeDegree>=0
With n as node, count(s) as counter
RETURN node, counter
04-28-2020 01:56 PM
it seems to work, but If I want to return also the nodes d
, I get 1
04-29-2020 12:28 AM
I do not know your model and data so unable to comment on the result
You just need to understand that when you are saying With n as node , count(s) as counter then you are doing count(s) group by n. When you need to group by d also then you need to check how many relationship are there between n and d .
04-29-2020 01:23 AM
The data are saved in my db in this way:
Friend
nodes there is a relationship between this node and a node user
Friend
there is a relathionship tagged_together
At the end I have result in this way grouping by n:
MATCH (n )
WHERE
ID(n) = 770903
OPTIONAL MATCH (n)-[s:TAGGED_TOGETHER]-(d)
WHERE
s.tagged_together >= 0 AND
((d.timestamp>'2016/01/01' AND d.timestamp<'2019/01/01') OR
(d.removed_timestamp>'2016/01/01' AND d.removed_timestamp<'2019/01/01')) AND
d.nodeDegree>=0
RETURN n , collect(d.name) , count(s)
All the sessions of the conference are now available online