我正在使用OrientDB 2.0。查询很简单,但我似乎无法弄明白。我有两个课程:User
和UserGroup
。为简化起见,User
只有username
和password
属性,而UserGroup只有一个id
属性。关系很简单:
User --- user_group --> UserGroup
其中user_group
是连接User
和UserGroup
顶点的边缘类。
我想要做的是让用户拥有某个用户名和密码UserGroup.id
等于 group1
到目前为止我所拥有的是:
select expand(in('user_group')[username='foo' and password='bar'])
from UserGroup
where id = 'group1'
但这对我不起作用。我做错了什么?
答案 0 :(得分:2)
create class User extends V
create property User.username string
create property User.password string
create class UserGroup extends V
create property UserGroup.id string
create class user_group extends E
create vertex User set username = 'foo', password = 'bar'
create vertex UserGroup set id = 'group1'
create edge user_group from (select from User where username = 'foo') to (select from UserGroup where id = 'group1')
select expand(in('user_group')[username='foo'][password='bar'])
from UserGroup
where id = 'group1'
答案 1 :(得分:0)
我想,经过几次尝试,我找到了答案:
select from
(select expand(in('user_group'))
from UserGroup
where id = 'group1')
where username='foo' and password='bar'
如果有人能提出更优雅的解决方案,那也很不错
答案 2 :(得分:0)
select
from (
select expand(in('user_group'))
from UserGroup
where id = 'group1'
)
where username='foo' and password='bar'