Neo4j如何获得前10个desc代码

时间:2016-07-13 17:38:32

标签: neo4j cypher

我有这种关系

MATCH(chatitems) - [r:PartOf] - >(团队) - [o:OwnedBy] - ()

我希望得到前10支队伍的teams.id和chatitems.id,并且命令desc。我需要保留teams.id和chatitems,因为我需要在其他比赛中使用

我先执行了两个查询

MATCH (chatitems)-[r:PartOf]->(teams)-[o:OwnedBy]-()
with distinct teams
order by teams.id DESC
with collect(teams)[0..10] as teams1
unwind teams1 as teamsid
return teamsid

结果

teamsid

"{""id"":62531}"
"{""id"":58852}"
"{""id"":53495}"
"{""id"":53235}"
"{""id"":49085}"
"{""id"":48730}"
"{""id"":48448}"
"{""id"":40690}"
"{""id"":39568}"
"{""id"":37480}"

团队代码是对的。

现在我想得到这些团队的聊天项目

我有查询

match (chatitems)-[r:PartOf]-(teamsChat)-[s:OwnedBy]-()
with teamsChat as teams,chatitems
order by teams.id desc
with  collect(distinct teams.id)[0..10] as teams1,chatitems
return teams1

结果

teams1

[6784]
[6889]
[6974]
[6868]
[6949]
[6838]
[7024]
[7726]
[6792]
[6797]
[6949]
[6779]
[22935]

团队错了。对于每个team.id可以有几个聊天项目。

1 个答案:

答案 0 :(得分:0)

这样的事情

match (t:teams)
with t as T
match (T)-[r:PartOf]-(c:chatitems)
with T, c.id as num order by num desc 
return {teamid:T.id, items:collect(num)[0..10]}