求助 怎么给排序分页结果去重
发布于 3 年前 作者 zhangxin123456 407 次浏览 来自 问答

556677.png

如图所示 MATCH (n1:paper {name:“Deep learning”}) CALL { WITH n1 MATCH (n1)-[r1:인용]-(n2)-[r2:인용]-(n3) WITH r1.weight+n2.LOG AS sreco,n2.name AS title return distinct title,sreco
UNION WITH n1 MATCH (n1)-[r1:인용]-(n2)-[r2:인용]-(n3) WITH r1.weight*r2.weight+n3.LOG AS sreco,n3.name AS title return distinct title,sreco}

return DISTINCT title, sreco ORDER BY sreco DESC LIMIT,sreco没有重复的没错,但现在titile又出现了重复 请问怎么让 title也只出现一次 且是与sreco配对的 最大值。 我要做的是title只出现一次每个sreco是与title对应的,且sreco是重复出现的title的最大值。

2 回复

可以参考下面这个查询,使用title对sreco分组,然后从sreco列表找到最大值输出

WITH [{title:'title1',sreco:'0.23213'},{title:'title1',sreco:'0.53213'},{title:'title2',sreco:'0.63213'},{title:'title3',sreco:'0.13213'}] AS list
UNWIND list AS map
WITH map.title AS title,map.sreco AS sreco
// 在你的查询中拼接下面这段语句
WITH title,COLLECT(sreco) AS sreco_list
RETURN title,apoc.coll.max(sreco_list) AS max_sreco

@crazyyanchao 感谢大佬 非常感谢

回到顶部