0
votes

I am trying to find a query for my graph which I created by jqassistant. But I just can't figure it out. My data looks like this:

I have several nodes representing a artifact: (Each row is a node)

name        version
===================
projectOne     001
projectTwo     001
projectOne     002
projectTwo     002
projectOne     009
projectOne     004
projectOne     029
projectTwo     003
projectTwo     010

What my query should return is two nodes:

projectOne  029
projectTwo  010

So I want the newest version of this nodes distinct by name. I know how to use DISTINCT and ORDER BY but I just can't figure out how to combine those two to get the desired output. Any ideas?

My final goal is to mark the newest versions. Then I want to point out every newest artifact which depends on artifacts which are not marked as newest.

Another possible solution to reach this would be to create a chain of predecessors. Then every artifact with no incoming predecessor would be the latest version. But that implies the same problem as I have with selecting the newest ones.

1

1 Answers

2
votes

Assuming all relevant nodes have the Foo label, the query is very simple:

MATCH (n:Foo)
RETURN n.name, MAX(n.version);

The MAX aggregation function finds the maximum version for each distinct name.