load csv

添加节点数据

  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/products.csv" AS row
  2. CREATE (n:Product)
  3. SET n = row,
  4. n.unitPrice = toFloat(row.unitPrice),
  5. n.unitsInStock = toInteger(row.unitsInStock), n.unitsOnOrder = toInteger(row.unitsOnOrder),
  6. n.reorderLevel = toInteger(row.reorderLevel), n.discontinued = (row.discontinued <> "0")
  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/categories.csv" AS row
  2. CREATE (n:Category)
  3. SET n = row
  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/suppliers.csv" AS row
  2. CREATE (n:Supplier)
  3. SET n = row

添加节点

  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/customers.csv" AS row
  2. CREATE (n:Customer)
  3. SET n = row
  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/orders.csv" AS row
  2. CREATE (n:Order)
  3. SET n = row

建立索引

  1. CREATE INDEX ON :Product(productID)

建立关系

  1. Match(p:Product),(n:Category)
  2. where p.categoryID = categoryID
  3. create(p)-[:part_of]->(n)
  1. MATCH (c:Customer),(o:Order)
  2. WHERE c.customerID = o.customerID
  3. CREATE (c)-[:PURCHASED]->(o)

查询
collect

  1. MATCH (s:Supplier)-->(:Product)-->(c:Category)
  2. RETURN s.companyName as Company, collect(distinct c.categoryName) as Categories

查询-限制了分类名称

  1. MATCH (c:Category {categoryName:"Produce"})<--(:Product)<--(s:Supplier)
  2. RETURN DISTINCT s.companyName as ProduceSuppliers

加载订单明细表

  1. LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/order-details.csv" AS row
  2. MATCH (p:Product), (o:Order)
  3. WHERE p.productID = row.productID AND o.orderID = row.orderID
  4. CREATE (o)-[details:ORDERS]->(p)
  5. SET details = row,
  6. details.quantity = toInteger(row.quantity)

查询客户订单数量

  1. MATCH (cust:Customer)-[:PURCHASED]->(:Order)-[o:ORDERS]->(p:Product),
  2. (p)-[:PART_OF]->(c:Category {categoryName:"Produce"})
  3. RETURN DISTINCT cust.contactName as CustomerName, SUM(o.quantity) AS TotalProductsPurchased