问题
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