sql - OrientDB 如何在一个查询中获取顶点及其边的结果集

标签 sql orientdb graph-databases

我一直在玩 OrientDB sql 查询以获得一个结果集,该结果集不仅包含顶点,还包含它们之间存在的内部边。

查询可以表示为:

  • 我想要所有与 project 相关的顶点(不包括项目本身)以及结果中包含的顶点之间的所有边

  • enter image description here

    这是我实现它的方式,但我认为这不是正确的方法。

    enter image description here
    select expand($union) let $vertices = ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ), $edges = ( select from ( select from E where @rid in ( select bothE() from ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ) ) where out in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) and in in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ), $union = unionall($vertices, $edges)
    和预期的结果:

    enter image description here

    此解决方案的问题:
  • 我必须多次遍历图形(首先获取顶点,然后获取边缘以最终合并结果)
  • 基本查询 select from V where label = 'project'也被执行了几次。

  • 有没有更好的方法来解决这个用例?

    谢谢。

    最佳答案

    试试这个查询:

    select expand($c)
    let $a=(traverse both(),bothE() from (select from V where label="project")),
    $b=(traverse bothE() from (select from V where label="project")),
    $c=difference($a,$b)
    

    关于sql - OrientDB 如何在一个查询中获取顶点及其边的结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34064874/

    相关文章:

    mysql - 无法创建表 'mydb.contact'(错误号 : 150)

    database - 如何在一个查询中检索树中每个节点的前 n 个子节点

    OrientDB SELECT 和子查询

    MySQL 优化 INSERT 速度因索引而变慢

    sql - 如果值存在于另一个数据库中,则从一个 mysql 数据库中选择信息

    mysql - 将 CSV 数据导入 mySQL 数据库中的表中

    c# - 模型的 OrientDB-NET.binary

    java - 升级 Neo4J 3.3.4 -> 3.4.0 缺少依赖项 "com.sun.jersey.multipart.FormDataParam",替代品是什么?

    mysql - 使用 Neo4j ETL CLI 工具从 MySQL 数据库加载时出现问题

    node.js - 避免 oriento 中的查询超时(OrientDB 的 Node.js 驱动程序)