Neo4j Cypher:联合中的相关变量

Neo4j Cypher:联合中的相关变量,neo4j,cypher,union,correlated-subquery,Neo4j,Cypher,Union,Correlated Subquery,我需要回答以下问题:根据商店销售额和所有其他城市的商店销售额加起来,排名前三的商店城市 使用以下查询 // Top 3 cities MATCH (t:Store)<-[:HasStore]-(s:Sales) WITH t.StoreCity AS StoreCity, t, sum(s.StoreSales) AS StoreSales ORDER BY sum(s.StoreSales) DESC LIMIT 3 // All other cities WITH StoreCity,

我需要回答以下问题:根据商店销售额和所有其他城市的商店销售额加起来,排名前三的商店城市

使用以下查询

// Top 3 cities
MATCH (t:Store)<-[:HasStore]-(s:Sales)
WITH t.StoreCity AS StoreCity, t, sum(s.StoreSales) AS StoreSales
ORDER BY sum(s.StoreSales) DESC LIMIT 3
// All other cities
WITH StoreCity, StoreSales, collect(t) AS TopThreeCities
MATCH (t1:Store)<-[:HasStore]-(s:Sales)
WHERE NOT(t1 IN TopThreeCities)
// JOIN of the two results -> I would need the UNION
RETURN StoreCity, StoreSales, "Other cities" AS StoreCity1, sum(s.StoreSales) AS StoreSales1
但我想获得

"A" 10
"B" 9
"C" 8
"Other Cities"  50
你知道怎么得到这个吗?我尝试了许多可能性,但没有成功:-(

使用工会:

// Top 3 cities
MATCH (t:Store)<-[:HasStore]-(s:Sales)
RETURN t.StoreCity AS StoreCity, sum(s.StoreSales) AS StoreSales
ORDER BY sum(s.StoreSales) DESC LIMIT 3
// All other cities
UNION
MATCH (t:Store)<-[:HasStore]-(s:Sales)
WITH t.StoreCity, sum(s.StoreSales) AS AllStoreSales
ORDER BY AllStoreSales DESC SKIP 3
RETURN "Other cities" AS StoreCity, sum(AllStoreSales) AS StoreSales
//前三大城市
匹配(t:商店)
// Top 3 cities
MATCH (t:Store)<-[:HasStore]-(s:Sales)
RETURN t.StoreCity AS StoreCity, sum(s.StoreSales) AS StoreSales
ORDER BY sum(s.StoreSales) DESC LIMIT 3
// All other cities
UNION
MATCH (t:Store)<-[:HasStore]-(s:Sales)
WITH t.StoreCity, sum(s.StoreSales) AS AllStoreSales
ORDER BY AllStoreSales DESC SKIP 3
RETURN "Other cities" AS StoreCity, sum(AllStoreSales) AS StoreSales