Return how many specific relationship there are for a specific node

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 ?

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

it seems to work, but If I want to return also the nodes d, I get 1

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 .

The data are saved in my db in this way:

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)