我有这个简单的数据集给你一些例子:
create class Customer extends V
create class City extends V
create class livesAt extends E
create property Customer.name String
create property City.id integer
create property City.location String
create vertex Customer set name="Tom"
create vertex Customer set name="John"
create vertex City set id=1, location="London"
create vertex City set id=2, location="Pune"
create edge livesAt from (select from Customer where name="Tom") to (select from City where id=1)
create edge livesAt from (select from Customer where name="John") to (select from City where id=2)
现在您可以使用不同的查询来检索您要查找的结果。
查询 1a:从客户开始(如您上面的查询)
select from Customer where out('livesAt').location in 'Pune'
输出:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
查询 1b:从客户重新开始
select from Customer where out('livesAt').location contains 'Pune'
输出:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
查询 1c:
select from Customer where out('livesAt')[location = 'Pune'].size() > 0
输出:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
查询 2:从城市开始(更直接)
select expand(in('livesAt')) from City where location = 'Pune'
输出:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
希望对你有帮助