Neo4j如何获取前10个desc代码 [英] Neo4j how to get first 10 desc codes

查看:210
本文介绍了Neo4j如何获取前10个desc代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种关系

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

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

我想从前10个团队中获得有序的desc和team.id和chatitems.id.我需要保留team.id和chatitems,因为我需要在其他比赛中使用

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

我首先执行两个查询是

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

团队代码正确.

现在我想获得这些团队的聊天消息

Now I want to get chatitems of these teams

我有查询

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可以有几个聊天项.

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

推荐答案

这样的事情

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

这篇关于Neo4j如何获取前10个desc代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆