Sql 在Neo4J中使用Cypher连接两个子查询

Sql 在Neo4J中使用Cypher连接两个子查询,sql,neo4j,cypher,Sql,Neo4j,Cypher,我有以下SQL查询: SELECT q1.customerId, q1.invoiceId, q2.workId, sum(q2.price) FROM (select customer.id as customerId, invoice.id as invoiceId, work.id as workId from customer, invoice, workinvoice, work where customer.id=invoice.customerid and invoice.id=w

我有以下SQL查询:

SELECT q1.customerId, q1.invoiceId, q2.workId, sum(q2.price)
FROM (select customer.id as customerId, invoice.id as invoiceId, work.id as workId from customer, invoice, workinvoice, work where customer.id=invoice.customerid and invoice.id=workinvoice.invoiceId and workinvoice.workId=work.id
) as q1, (select work.id as workId, sum((price * hours * workhours.discount) + (purchaseprice * amount * useditem.discount)) as price from worktype,workhours,work,warehouseitem,useditem where worktype.id=workhours.worktypeid and workhours.workid=work.id and work.id=useditem.workid and useditem.warehouseitemid=warehouseitem.id group by work.id
) as q2
WHERE q1.workId = q2.workId group by q1.invoiceId;
此查询应返回每个客户的每张发票的工作价格总和


我想知道如何在Neo4J中进行这种查询。我知道有工会。然而,这似乎确实符合我的要求。我需要做两个子查询,并从同一个节点将它们连接起来,就像在那个SQL示例中一样。使用Cypher执行此操作的正确方法是什么?

这里有一个非常复杂的示例,说明如何在Cypher中执行连接:

基本上,技术是运行第一个查询,收集结果。然后运行第二个,收集结果。然后展开第二个,使用过滤器进行匹配,并返回结果

在真正简化的形式中,它看起来像这样:

CALL something() YIELD a, b
WITH collect({ a: a, b: b }) as resultSet1
CALL somethingElse YIELD a, c
WITH resultSet1, collect({ a: a, c: c }) as resultSet2

UNWIND resultSet2 as rec
WITH [item in resultSet1 WHERE item.a = rec.a][0] as match, rec

RETURN match.a, match.b, rec.c

列表理解位基本上是执行连接。这里我们加入到“a”字段中。

我找到了我想要的解决方案:


匹配(库存:发票)-[:工作\发票]->(w:工作)(i:项目)与库存匹配,工时价格+总价(u.amount*u.discount*i.purchaseprice)作为工作价格返回库存,总价(WorkTempPrice)作为发票价格

您能否澄清以下表格的来源:
价格
小时数
采购价格
,以及
金额
?另外,这些表中哪些只是连接表?您尚未提供此数据的图形模型,因此我们需要您提供一些额外信息,以确定哪些是相关的,哪些应该包括在内,图形数据模型中不包含且应该排除的内容。对涉及的表和每个表的相关数据进行口头描述会有所帮助。此外,如果您能指出哪些表是1-1联接的,哪些表是1-many联接的,那么也可以在中看到表定义。看看createTables()方法。