Neo4j how to get first 10 desc codes

天大地大妈咪最大 提交于 2019-12-13 07:00:26

问题


I have this relation

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

I want to get teams.id and chatitems.id from first 10 teams distinct and ordered desc. I need to keep teams.id and chatitems because I need to use in other match

I executed two queries first is

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

Results are

teamsid

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

Team codes are right.

Now I want to get chatitems of these teams

I have the query

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

Results are

teams1

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

Teams are wrong. For each team.id can have several chatitems.


回答1:


how about something like this

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]}


来源:https://stackoverflow.com/questions/38358351/neo4j-how-to-get-first-10-desc-codes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!