Neptune Gremlin - 如何写分组的where count > 2

问题描述 投票:1回答:1

如何在gremlin中实现和SQL一样的效果?

select A.id from A group by A.id having count(A.id)>2

更进一步的问题是,我可以返回所有A的属性,而不仅仅是id吗?

例如,下面的查询返回多个V,其中一些V的Id是重复的。我只想得到那些重复的V,不包括count()==1。

g.V().hasLabel('A').as('Root').until(__.hasId('abc','xyz')).repeat(__.outE('A-B','A-C').inV()).select('Root').valueMap(true).toList()

gremlin
1个回答
4
投票

你的问题中有一些不清楚的地方。

id是一个唯一的值,我猜你的意思是不同的属性或者一个顶点多次关联到一个组。

对于属性。

g.V().hasLabel('Group').
  has('name', within('A', 'B')).out('in').
  group().by('prop1').by().unfold().
    select(values).
  where(count(local).is(gt(1))).unfold().
  valueMap(true)

是指多边形

g.V().hasLabel('Group').
  has('name', within('C')).out('in').
  groupCount().by().unfold().
  where(select(values).
    is(gt(1))).select(keys).
  valueMap(true)

例如: https:/gremlify.com9k。

© www.soinside.com 2019 - 2024. All rights reserved.