如果node2.parameter = 0,则返回node.name

时间:2015-06-05 09:45:19

标签: neo4j cypher

某人 x 某些 y为某些价格 永远时,它会被调用"的&#34 ;.但是,如果某些时间 某人 x 某些 y某些价格,则会将其称为&strong #34;的&#34 ;.当它的操作没有成本时,它被称为" 目前"。

我想使用neo4j进行此操作。但我不想为每种交换类型创建单独的节点集,因为关键是要显示它是如何相同的,但操作名称取决于变量参数 - 成本时间即可。

http://i.stack.imgur.com/ymy2L.png

CREATE 
(n:Person { name: "Seller" }),
(b:Person { name: "Buyer" }),
(ntt:Time { name: "Time", forever: 0}),
(nt:Goods { name: "Goods" }),
(nd:Price { name: "Price", zero: 0 }),
(nd2:OperationName { name: "Sell" }),
(nd3:OperationName { name: "Rent" }),
(nd4:OperationName { name: "Gift" }),
(b)-[:sold]->(nt),
(b)-[:rented_out]->(nt),
(b)-[:presented]->(nt) 
RETURN n,b,ntt,nt,nd, nd2, nd3, nd4

如果价格 ,如何返回 OperationName.name:"礼品"

1 个答案:

答案 0 :(得分:0)

这是一个建议的简单模型。 Transaction节点具有price属性和可选的expires属性,是"提供"一个Person和"收到"另一个,并与Goods项目相关联。

在这里,我创建了两个样本交易:

CREATE
  (a:Person { name: "A" })-[:PROVIDED]->(t:Transaction { price: 13997.95, expires: 1234567})-[:ITEM]->(:Goods { name: "Truck" }),
  (b:Person { name: "B" })-[:RECEIVED]->(t),
  (b)-[:PROVIDED]->(t2:Transaction { price: 0 })-[:ITEM]->(:Goods { name: "Candy" }),
  (c:Person { name: "C" })-[:RECEIVED]->(t2);

在这里,我会转发有关所有交易的信息 - 包括它是否为现在(与购买相比)以及是否为租赁:

MATCH
  (provider:Person) -[:PROVIDED]-> (t:Transaction) -[:ITEM]-> (goods:Goods), 
  (receiver:Person) -[:RECEIVED]-> (t)
RETURN
  t.price = 0 AS isPresent, t.expires IS NOT NULL AS isRental, provider.name, receiver.name, t.price, goods.name, t.expires;

结果如下:

+------------------------------------------------------------------------------------------+
| isPresent | isRental | provider.name | receiver.name | t.price  | goods.name | t.expires |
+------------------------------------------------------------------------------------------+
| false     | true     | "A"           | "B"           | 13997.95 | "Truck"    | 1234567   |
| true      | false    | "B"           | "C"           | 0        | "Candy"    |           |
+------------------------------------------------------------------------------------------+

请参阅this console