繁体   English   中英

Neo4j 过滤器使用计数

[英]Neo4j Filter Using Count

我只需要找到为超过 1 个组织(有特定交易)工作的员工。 我试图用count进行过滤,所以如果列出的名称>1或者他们有>1 company name与之关联,但两者都不起作用,不知道为什么。

我已经包含了//我尝试过的其他方法(不返回任何结果)。

MATCH (employee:Employee)-[Employee:WORKS_AT]->(retailer),(customer:Customer)- 
[transaction:SHOPPED_AT]->(retailer)
WHERE transaction.status = "XYZ"  
WITH employee.name AS `Employee Name`, collect(DISTINCT retailer.name) AS `Retailer Name`, 
count(retailer.name) as cnt
//WHERE cnt >1
WHERE `Retailer Name`>1
RETURN `Employee Name`, `Retailer Name`

使用下面的代码,我已经能够通过一些员工的姓名获得多个零售商的列表,但仍然包括只有一个雇主的其他人(如詹姆斯)。 或者我可以将每个名称和零售名称都列在一个列表中,所以如果我可以只取那些重复出现的员工姓名,并且出现多次,那将有效,但没有。

    MATCH (employee:Employee)-[Employee:WORKS_AT]->(retailer),(customer:Customer)- 
    [transaction:SHOPPED_AT]->(retailer)
    WHERE transaction.status = "XYZ"  
    WITH employee.name AS `Employee Name`, collect(DISTINCT retailer.name) AS `Retailer Name`
    RETURN `Employee Name`, `Retailer Name`

   name retailer 
   John  [abc, def]
   James [abc] 
   -OR-
   name retailer
   John abc
   John def
   James abc
(but how to filter for >1)


看起来您的初始MATCH语句存在问题,但如果无法访问数据 model,我无法准确说出它是什么。 你能试着把它变成一个匹配语句吗?

MATCH (employee:Employee)-[:WORKS_AT]->(retailer)<-[transaction:SHOPPED_AT]-()
WHERE transaction.status = "XYZ"  
WITH DISTINCT employee.name AS `Employee Name`, collect(DISTINCT retailer.name) AS `Retailer Name`, 
count(retailer.name) as cnt
WHERE cnt > 1
RETURN `Employee Name`, `Retailer Name`

此查询的工作方式应该是,对于每个Employee ,您收集与他们有WORKS_AT关系的所有零售商,其中retailer至少有一个状态为"XYZ"SHOPPED_AT交易。 然后,您可以根据员工是否在不止一家retailer工作来筛选他们。

这应该这样做:

// Find transcation of the desired type
MATCH (employee:Employee)-[:WORKS_AT]->(retailer)<-[transaction:SHOPPED_AT {status:'XYZ'}]-(:Customer)

// Collect the distinct retailers and filter for collections with > 1 retailer
WITH employee, collect(DISTINCT retailer) AS retailers
WHERE SIZE(retailers) >  1

// Unwind to list of unique retailers (only necessary if you want to return the retailer name)
UNWIND retailers AS retailer
RETURN employee.name,retailer.name

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM