格雷姆林 - 组中的值求和



我已经尝试了几天来得到以下结果:

我有这个数据集:

e1 = g.addV('company').property('name', 'company-1').next()
e2 = g.addV('company').property('name', 'company-2').next()
p1 = g.addV('product').property('name', 'product-1').next()
p2 = g.addV('product').property('name', 'product-2').next()
p3 = g.addV('product').property('name', 'product-3').next()
i1 = g.addV('tax').property('name', 'tax-1').next()
i2 = g.addV('tax').property('name', 'tax-2').next()
g.addE('taxes').from(i1).to(p1).property('amount', 10)
g.addE('taxes').from(i2).to(p2).property('amount', 15)
g.addE('taxes').from(i1).to(p3).property('amount', 20)
g.addE('taxes').from(i2).to(p3).property('amount', 20)
g.addE('sells').from(e1).to(p1).property('price', 10)
g.addE('sells').from(e1).to(p2).property('price', 15)
g.addE('sells').from(e2).to(p2).property('price', 20)
g.addE('sells').from(e2).to(p3).property('price', 25)

我需要对公司销售的所有产品求和(公司-1 = 25,公司-2 = 45(。 目前我被困在以下查询中:

g.V().hasLabel('company').as('e').outE('sells').as('f').inV().as('p').inE('taxes').as('i').outV().select('e', 'p', 'f', 'i').by('name').by('name').by('price').by('amount').group().by('e')

关于我如何做到这一点的任何提示? 另外,如果有人可以给我一个例子,说明我如何做总和,但考虑到税收,例如:价值 = 产品 * (1 + (金额/100((

我认为这首先按公司分组,然后在边缘对价格求和,从而为您提供了所需的内容:

g.V().hasLabel('company').as('e').
outE('sells').as('f').
group().
by(select('e').values('name')).
by(values('price').sum())

最新更新