0
在下面我怎麼找存在於路徑的用戶的平均年齡查詢:Cypher支架查詢發現平均年齡在路徑
start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p = begin--()--end
return extract(n in nodes(p): n.Age);
在下面我怎麼找存在於路徑的用戶的平均年齡查詢:Cypher支架查詢發現平均年齡在路徑
start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p = begin--()--end
return extract(n in nodes(p): n.Age);
剛剛殺青你的第一個查詢:
start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match begin--middle--end
where has(middle.Age)
return sum(middle.Age)/count(middle);
我相信,但是,你問所有用戶User_2到User_32:
start n=node(*)
where has(n.Age) and Id(n)>1 and Id(n)<33
return sum(n.Age)/count(n);
但在最後一種情況下,如果你問˚F或者用戶1和USER32之間的路徑中的所有用戶:
start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p=begin-[*..]-end
with extract(n in nodes(p): n)
where has(n.Age)
return sum(n.Age)/count(n);
編輯:我剛剛發現,你可以更換總和(n.Age)/數(N);簡單地與平均(年齡)
所以,在1.9你現在可以做到這一點與reduce
。
start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p = begin--()--end
return reduce(total=0, n in nodes(p): total + n.Age)/length(p) as avgAge;
這不是路徑上的平均年齡,而是結果集上的平均年齡。 –