示例数据
g.addV('result').
property('marks', 100).
property('subject', 'Maths').
property('student', A)
g.addV('result').
property('marks', 50).
property('subject', 'English').
property('student', A)
我有多个学生的详细信息,我想为那些最高分低于 80 分的学生获取学生姓名和科目。
我试过这个,但分组后过滤器不起作用
g.V().
hasLabel('result').
order().
by('marks').
group().
by('student').
by(limit(1)).
has('marks', lte(80)).
project('Student', 'Marks').
by('student').
by('marks')
还有其他选择吗?
注意:我想编写一个在Cosmos DB Gremlin API中支持的查询
您可以在group
步骤中筛选结果。 喜欢这个:
g.V().hasLabel('result').
order().by('marks').
group().
by('student').
by(has('marks', lte(80)).
project('Subject', 'Marks').
by('subject').by('marks').fold())
但我认为最好先过滤结果:
g.V().hasLabel('result').
has('marks', lte(80)).
group().
by('student').
by(
project('Subject', 'Marks').
by('subject').by('marks').fold())
如果您有更大的查询,并且仍然需要在group
后进行筛选,则可以使用select
g.V().hasLabel('result').
order().by('marks').
group().
by('student').unfold().
select(values).unfold().
has('marks', lte(80)).
project('Student', 'Marks').
by('student').by('marks')
示例:https://gremlify.com/d4zw5qg1hc9y