在子查询中按属性过滤边缘 - orientdb sql

时间:2015-07-07 03:43:54

标签: database traversal graph-databases orientdb

我有以下OrientDB SQL查询,它返回用户#12:0所有朋友的用户名和国家/地区。

select 
   username, country 
from (select 
         expand( both('friends') ) 
      from 
         users 
      where 
         @rid = #12:0)

但是,friends边缘的属性years带有整数。我只希望那些#12:0的朋友friends.years > 3

我试过了

SELECT username, country from (SELECT expand(outE('friends')[years > 3].inV()) FROM #12:0)

SELECT username, country from (SELECT expand(both('friends')[years = 2]) FROM #12:0)

和同一查询的各种游戏。

谢谢,全部!

2 个答案:

答案 0 :(得分:2)

create class User extends V
create property User.username string
create property User.country string

create class friends extends E
create property friends.year integer  


create vertex User content {'username':'u1', 'country':'PT'}
create vertex User content {'username':'f1', 'country':'AW'}
create vertex User content {'username':'f2', 'country':'CN'}

create edge friends 
from (select from User where username = 'u1')
to (select from User where username = 'f1')
content {'years':3}

create edge friends 
from (select from User where username = 'f2')
to (select from User where username = 'u1')
content {'years':4}

我相信这是你的情况。你可以:

select expand(bothE('friends')[years = 3].inV()) 
from (select from User where username = 'u1')

但是,据我所知,还不支持以下内容:

select expand(bothE('friends')[years > 3].inV()) 
from (select from User where username = 'u1')

答案 1 :(得分:0)

另一种选择是将核心查询与另一个嵌套查询包装在一起:

select * from (
select expand(both('friends')) 
from (select from User where username = 'u1')
)
where years > 3