我在这个简单的玩具示例中评估OrientDB和Neo4j:
eid
mid
标识,并且start
和end
属性编码其开始和结束日期时间。两个实体都由不同类别的顶点表示,即Employee
和CalendarEvent
,它们由Involves
边连接,指定CalendarEvent-[Involves]->Employee
。
我的任务是编写一个查询,为每对员工返回他们第一次会面的日期/时间以及他们共同参加的会议次数。 在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
但对我来说似乎过于复杂。 有人知道是否有更简单的方法来表达同一个查询吗?
答案 0 :(得分: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语句中拥有更多运算符,查询将更短