如何根据属性对属性进行分类

时间:2016-04-22 01:54:53

标签: neo4j

我有一个像这样的实体类:

@NodeEntity
public class Patent {

    @GraphId
    private Long patentId;

    private String patentName;

    //2016-02-01
    private String authorizedTime;

    private String patentNumber;

    @Fetch
    @RelatedTo(type = "authorizedPerson")
    private Set<Researcher> authorizedPersons = new HashSet<Researcher>();

    private String createTime;

    private String description;

我想得到这样的结果:

年总计 2013 6
2014 7

我尝试使用此Cypher查询:

match (n1:Patent)
with collect( DISTINCT subString(n1.authorizedTime,0,4)) as coll,subString(n1.authorizedTime,0,4) as val
return coll, reduce(s=0, val IN coll | s + 1) as numByY ;

但没有成功。

如何根据属性对属性进行分类?

非常感谢!

1 个答案:

答案 0 :(得分:0)

此查询应每年返回该年份的节点数,按年份排序:

MATCH (n1:Patent) 
RETURN LEFT(n1.authorizedTime, 4) AS year, COUNT(*) AS total 
ORDER BY year;