代码之家  ›  专栏  ›  技术社区  ›  Late Developer

Neo4J返回与一个特定节点链接的所有标签的列表

  •  -2
  • Late Developer  · 技术社区  · 6 年前

    其中,下面的cypher命令给出了所有节点的列表

    match(n) return distinct labels(n), count(*)
    

    我想做同样的事情,但对于一个节点,例如。

    match(p:Person {name: "dave"} return distinct labels(n), count(*)
    

    我尝试过这个,但它只返回一个计数

    我需要这个人下面有标签总数的列表

    **labels(n)**          **count(*)**
    ['Address']              2
    ['jobs']                 1
    ['cars']                 3
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Tezra    6 年前

    match(p:Person {name: "dave"} return distinct labels(n), count(*)

    正在计算行数(如果没有聚合,则始终为1)。您将以数组的形式返回标签,因此真正需要的是数组长度

    match(n) return distinct labels(n), SIZE(LABELS(n))

    根据你的问题,我想你真的想这样解开标签

    match(n) UNWIND LABELS(n) as label WITH label RETURN DISTINCT label, count(label)

        2
  •  0
  •   Late Developer    6 年前

    感谢您的帮助,但这仍然返回1的计数。我刚刚想出了如何得到我需要的东西: Match (p:Person{name:"dave"})-[*]->(c) return distinct labels(c), count(*)