我是Cypher和Neo4j的新手。我有一组标有“Line”的节点,每一行都是一个长字符串,例如:
0067011990999991950051507004+68750+023550FM-12+038299999V0203301N00671220001CN9999999N9+00001+99999999999
我关注的是两个子字符串:year
和temp
match(l:Line)
return toInteger(substring(l.line,15,4)) as year, toInteger(substring(l.line,87,5)) as temp
limit (5)
为了给出:
year temp
1941 44
1942 90
1942 12
1948 100
1948 -21
我需要为每个唯一的年份值创建一组标记为“Year”的节点,为每个唯一的临时读数标记为“Temp”的一组noes。我还需要使用关系has_temp将每年与其临时读数联系起来。 (然后以年份的desc排序顺序打印年份,临时读数和关系类型。
非常感谢任何帮助。
答案 0 :(得分:0)
试试这个:
match(l:Line)
with toInteger(substring(l.line,15,4)) as year,
toInteger(substring(l.line,87,5)) as temp
MERGE (y:Year{value:year})
MERGE (t:Temp{value:temp})
MERGE (y)-[s:has_temp]->(t)
RETURN year,temp,type(s) as rel_type order by year desc
如果您想稍后检查它是如何导入节点的,您可以这样做:
MATCH (y:Year)-[r]->(t:Temp)
RETURN y.value as year,t.value as temp,type(r) as re_tzpe order by year desc