행위

History&FiguresOfChina(2025)Neo4j Queries

CNUDH

중국의 역사와 인물(2025) 페이지로 가기



Neo4j Query 샘플





생성


① 단일 노드 생성


[생성된 노드 확인 하기 위해서는 return a〕
-ex) create (a:label명{gid:'gid명', class:'class명', name:'대표명칭', refurl:'외부정보링크'})

create (a:label명{property명:'property값'})



② 특정 라벨(label)의 노드 속성(properties) 및 값(value)을 생성


match (a:label명) set a. property명=“property값”



③ 엣지 데이터 생성


〔생성된 엣지 데이터 확인 하기 위해서는 return a, r, b〕

match (a{property명:'property값'}) match(b{property명:'property값'})
create (a) - [r:relation명] -> (b)



④ 관계 속성을 지닌 엣지 데이터 생성


〔생성된 엣지 데이터 확인 하기 위해서는 return a, r, b〕

match (a{property명:'property값'}) match(b{property명:'property값'})
create (a) - [r:relation명{property명:'property값'}] -> (b)



출력:기초


① 모든 데이터를 출력


Desktop 버전에서는 모든 데이터가 출력되며, AuraDB에서는 Node 데이터만 출력됨.

match (n) return n
= match (n) return *

AuraDB에서 모든 데이터 출력 쿼리

match (a) optional match (a)-[r]-(b) return a, r, b
= match (a) optional match (a)-[r]-(b) return *



② 관계(relation)를 갖고 있는 모든 데이터를 출력


match (a)-[r]-(b) return a, r, b



③ 특정 라벨(label)에 속하는 데이터를 출력


match (a:label명) return a



④ 여러 관계(relation)를 가지고 있는 데이터 출력


relation명은 2개 이상 사용 가능

match (a:label명)-[r:relation명①|relation명②]-(b) return a, r, b



출력:관계


① 특정 관계(relation)를 갖고 있는 모든 데이터를 출력


match (a) -[r:relation명]- (b) return a, r, b
= match (a:label명)-[r]-(b) where type(r)="relation명" return a, r, b

② 특정 관계 속성(properties) 값(value)을 기준으로 데이터를 출력


match (a) -[r:relation명{property명:'property값'}]- (b) return a, r, b
= match (a) -[r:relation명]- (b) where r.property명='property값' return a, r, b

③ 특정 관계 속성(properties) 값(value)이 들어가는 데이터를 출력


match (a) -[r]- (b) where r.property명 contains 'property값' return a, r, b

④ 특정 관계(relation)를 가지지 않는 데이터 출력


match (a:label명)-[r]-(b) where not type(r)="relation명" return a, r, b




출력: 간편하게!


match문에 입력한 변수를 *으로 받기(*: 'all'을 뜻함)


match 쿼리 return *




오름/내림차순


노드 개수를 오름/내림차순으로 보이기


-예시1-1) 사건이 가장 많이 일어난 해는 언제일까?(A조)

MATCH (t:Time)<-[:OccurredOn]-(e:Event)
RETURN t.name AS 연도, count(e) AS 사건수
ORDER BY 사건수 DESC

-예시1-2) 1919년에 일어난 모든 사건을 시간순으로 보여줘.(B조)

MATCH (e:Event)-[:OCCURRED_ON]->(t:Time)
WHERE t.year = '1919'
RETURN t.name AS 날짜, e.name AS 사건명
ORDER BY 날짜 ASC



삭제


① 특정 라벨(label)의 노드 속성(properties)을 삭제


Match (a:label명) remove a. property명 Return a

② 모든 Node 삭제


Match (n) Delete n Return n

③ 모든 Node와 Edge 삭제


Match (n) Detach Delete n Return n

④ 특정 라벨(label)의 모든 Node 삭제


Match (a:label명) Delete a Return a

⑤ 특정 Edge 삭제


Match (a) – [r:relation명] – (b) Delete r