CYPHER强制GROUP BY for HAVING子句

时间:2016-08-31 11:01:49

标签: neo4j cypher

我有这个SQL查询,我需要转换为Cypher。我知道aggegations是隐含的,但在这种情况下,我需要在返回之前完成聚合,因为我需要HAVING子句的结果。

SELECT c.CustomerKey, SUM(c.YearlyIncome/c.TotalChildren) AS value
FROM  Customer c, Geography g
WHERE c.GeographyKey=g.GeographyKey AND g.Name ='Australia'
GROUP BY c.CustomerKey HAVING SUM(c.YearlyIncome/c.TotalChildren) >
                (SELECT SUM(c.YearlyIncome/c.TotalChildren)*0.0005
                FROM Customer c, Geography g
                WHERE c.GeographyKey=g.GeographyKey AND g.Name ='Australia')
ORDER BY value DESC;

我能够创建Cypher查询,直到这一点,但是GROUP BY ... HAVING部分丢失了,我不知道怎么做。

MATCH (c:Customer)-[:GEOGRAPHY]->(g.Geography)
WHERE g.Name='Australia'
(...) 
WITH SUM(c.YearlyIncome/c.TotalChildren) AS value
RETURN c.CustomerKey, value
ORDER BY value DESC

0 个答案:

没有答案