我正在尝试进行一个查询,以返回类之间的信息(我计划稍后使用此查询的输出将其转换为边缘)
这是我的测试设置(我正在使用OrientDB 3.0.14):
CREATE CLASS users
INSERT INTO users CONTENT {"name": "user1", "state_code": "CA"}
INSERT INTO users CONTENT {"name": "user2", "state_code": "VA"}
INSERT INTO users CONTENT {"name": "other3", "state_code": "FL"}
CREATE CLASS states
INSERT INTO states CONTENT {"code": "CA", "name": "California"}
INSERT INTO states CONTENT {"code": "VA", "name": "Virginia"}
INSERT INTO states CONTENT {"code": "FL", "name": "Florida"}
现在,此查询工作正常,我可以看到预期的结果:
SELECT name, state_code, $state FROM users LET $state=(SELECT FROM states WHERE code=$parent.$current.state_code)
+----+------+----------+---------------------------+
|# |name |state_code|$state |
+----+------+----------+---------------------------+
|0 |user1 |CA |[{code:CA,name:California}]|
|1 |user2 |VA |[{code:VA,name:Virginia}] |
|2 |other3|FL |[{code:FL,name:Florida}] |
+----+------+----------+---------------------------+
因此,我尝试使用以下方法添加子查询来过滤并仅返回用户中的某些记录:
SELECT name, state_code, $state FROM (SELECT FROM users WHERE name LIKE 'user%') LET $state=(SELECT FROM states WHERE code=$parent.$current.state_code)
+----+-----+----------+---------------------------+
|# |name |state_code|$state |
+----+-----+----------+---------------------------+
|0 |user1|CA |[{code:CA,name:California}]|
|1 |user2|VA |[{code:CA,name:California}]|
+----+-----+----------+---------------------------+
我无法找到一种方法来使计算出的值$state
返回正确的值,似乎只能使用第一条记录吗?
非常感谢您提供的帮助,以帮助您解决此查询。