【问题标题】:2-steps query in OrientDBOrientDB 中的两步查询
【发布时间】:2015-10-29 08:23:22
【问题描述】:

我在这个由以下组成的简单玩具示例中评估 OrientDB 和 Neo4j:

  • 员工,由eid 标识
  • 会议,由mid 标识,并具有编码其开始和结束日期时间的startend 属性。

这两个实体由不同类别的顶点表示,即EmployeeCalendarEvent,它们由指定CalendarEvent-[Involves]->EmployeeInvolves 边连接。

我的任务是编写一个查询,为每对员工返回他们第一次会议的日期/时间以及他们共同参加的会议次数。 在 Cypher 中,我会写如下内容:

MATCH (e0: Employee)<-[:INVOLVES]-(c:CalendarEvent)-[:INVOLVES]->(e1: Employee)
WHERE e0.eid > e1.eid
RETURN e0.eid, e1.eid, min(c.start) as first_met, count(*) as frequency

我为 OrientDB 编写了以下查询:

SELECT eid, other, count(*) AS frequency, min(start) as first_met
FROM (
  SELECT eid, event.start as start, event.out('Involves').eid as other
  FROM (
    SELECT 
    eid, 
    in('Involves') as event
    FROM Employee UNWIND event
    ) UNWIND other ) 
GROUP BY eid, other

但这对我来说似乎过于复杂。 有谁知道是否有更简单的方法来表达相同的查询?

【问题讨论】:

  • 参数nt是什么意思?
  • 对不起,我忘记换了。我应该写“开斋节”。我已经编辑了问题。

标签: orientdb


【解决方案1】:

是的,您的查询是正确的,这是您在当前版本 (2.1.x) 中必须执行的操作。

从 2.2 开始,使用 MATCH 语句 (https://github.com/orientechnologies/orientdb-docs/blob/master/source/SQL-Match.md),您将能够编写与 Cypher 版本非常相似的查询:

select eid0, eid1, min(start) as firstMet, count(*) from (
    MATCH {class:Person, as:e0}.in("Involves"){as: meeting}.out("Involves"){as:e1}
    return e0.eid as eid0, e1.eid as eid1, meeting.start as start
) group by eid0, eid1

这个功能直到测试版,可能在最终版本中你会在 MATCH 语句本身中有更多的操作符,查询会更短

【讨论】:

  • Grazie Mille,路易吉 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多