If I have a query along the lines of MATCH (g:Gene)-[r]-() RETURN DISTINCT type(r), count(r)
I can get a breakdown of the connections a gene node has, what type of relationships and how many of these.
Say I have a list of genes with which I want to do the same query, to get a pivot table, relationship types in rows, genes in columns, each individual cell in the table being the count of one type of relationship that gene has. How could I do this? I tried to connect two queries with a UNION ALL:
MATCH (g:Gene {name: "G1"})-[r]-(n)
RETURN DISTINCT type(r), count(r) as g1
UNION ALL MATCH (g:Gene {name: "G2"})-[r]-(n)
RETURN DISTINCT type(r), count(r) as g2
this returns an error about column names not being the same. If I make sure both returns have the same columns:
MATCH (g:Gene {name: "G1"})-[r]-(n)
RETURN DISTINCT type(r), null as g2, count(r) as g1
UNION ALL MATCH (g:Gene {name: "G2"})-[r]-(n)
RETURN DISTINCT type(r), null as g1, count(r) as g2
then I get duplicate rows, values being null for one gene and then the other. I also tried using UNWIND with a list then I get the two tables returned concatenated vertically instead (i.e. rows duplicated).
What I am trying to do should not be that difficult, what I am doing wrong?