#账户
create (accountHolder1:AccountHolder{FirstName:"John",LastName:"Doe",UniqueId:"JohnDoe"})
create (accountHolder2:AccountHolder{FirstName:"Jane",LastName:"Appleseed",UniqueId:"JaneAppleseed"})
create (accountHolder3:AccountHolder{FirstName:"Matt",LastName:"Smith",UniqueId:"MattSmith"})
#地址
create (address1:Address{Street:"123 NW 1st Street",City:"San Francisco",State:"California",ZipCode:"94101"})
//账户1 。2.3 关联到地址1上去
Match
1 create (accoutHolder1)-[:HAS_ADDRESS]->(address1),
2 (accoutHolder2)-[:HAS_ADDRESS]->(address1),
3 (accoutHolder3)-[:HAS_ADDRESS]->(address1)
实际: 账户1 id为 87675 账户2的id 87604 账户3的id 87605
MATCH (accoutHolder1:AccountHolder),(address1:Address) where id(accoutHolder1)=87675 and id(address1)=87606
create (accoutHolder1)-[r:HAS_ADDRESS]->(address1)
return r;
#创建电话号码 1
Create (phoneNumber1:PhoneNumber {PhoneNumber:"555-555-5555"}) 的到id 是87622
//把账户1和账户2关联到电话号码1上
MATCH (accoutHolder1:AccountHolder),(b:PhoneNumber) where id(accoutHolder1)=87675 and id(b)=87622
create (accoutHolder1)-[r:HAS_PHONENUMBER]->(b)
return id(r);
//创建社会安全码SSN1 得到的id是87623
Create (ssn1:SSN {SSN:"241-555-1234"})
//把账户2和账户3关联到SSN1上去
MATCH (accoutHolder1:AccountHolder),(b:SSN) where id(accoutHolder1)=87604 and id(b)=87623
create (accoutHolder1)-[r:HAS_SSN]->(b)
return id(r);
//创建SSN2 并且管理到 账户1上去
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87675
create (ssn2:SSN{SSN:"241-23-4567"})-[r:HAS_SSN]->(accoutHolder1)
return id(r);
//创建信用卡号1并管理到账户1上
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87675
create (creditCard1:CreditCard{AccountNumber:"1234567890123456",
Limit:5000,Balance:"1442.23",ExpirationDate:"01-20",
SecurityCode:"123"})-[r:HAS_CREDITCARD]->(accoutHolder1)
return id(r);
//创建信用卡号2并管理到账户2上
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87604
create (creditCard1:CreditCard{AccountNumber:"1234567890123456",
Limit:4000,Balance:"2345.56",ExpirationDate:"02-20",
SecurityCode:"456"})-[r:HAS_CREDITCARD]->(accoutHolder1)
return id(r);
//创建银行帐号1并关联到帐户1
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87675
create (bankAccount1:BankAccount{AccountNumber:"2345678901234567",
Balabce:7054.43})<-[r:HAS_BANKACCOUNT]-(accoutHolder1)
return id(r);
//创建银行帐号2并关联到帐户2
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87604
create (bankAccount1:BankAccount{AccountNumber:"3456789012345678",
Balabce:4231.12})<-[r:HAS_BANKACCOUNT]-(accoutHolder1)
return id(r);
//创建无抵押贷款2 并关联到账户2
MATCH (accoutHolder1:AccountHolder)where id(accoutHolder1)=87604
create (unsecuredLoan:UnsecuredLoan{AccountNumber:"4567890123456789-0",
Balabce:9045.53,APR: .0541,LoanAmount:12000.00})<-[r:HAS_UNSECUREDLOAN]-(accoutHolder1)
return id(r);
最终查询:
Match (accountHolder:AccountHolder)-[]-(contactInformation)
With contactInformation,
count(accountHolder) AS RingSize
Match (contactInformation)-[]-(accountHolder)
With collect(accountHolder.UniqueId) AS AccountHolders,
contactInformation,RingSize
Where RingSize>1
Return AccountHolders AS FraudRing,
labels(contactInformation) AS ContactType,
RingSize
Order BY RingSize Desc
//最终查询分段
Match (accountHolder:AccountHolder)-[]-(contactInformation)
With contactInformation,
count(accountHolder) AS RingSize
return contactInformation , RingSize