OrientDB查询产品及其最后注释
我有两个顶点类:Product和Comment。每个产品都可以有很多评论。注释有两个属性:日期和消息 {Product}-->{Comments} 我需要编写一个查询来检索所有带有最后一条评论消息的产品。OrientDB查询产品及其最后注释,orientdb,Orientdb,我有两个顶点类:Product和Comment。每个产品都可以有很多评论。注释有两个属性:日期和消息 {Product}-->{Comments} 我需要编写一个查询来检索所有带有最后一条评论消息的产品。 产品信息日期 A最后一次评论为2016年1月1日 B xxx 22/01/2011 ... 我找不到有关此类查询的任何文档。如果您有一个边缘连接产品和注释,并且总是按时间顺序插入,则可以执行以下操作: SELECT Name, last(out()).Message, last(out()
产品信息日期
A最后一次评论为2016年1月1日
B xxx 22/01/2011
...
我找不到有关此类查询的任何文档。如果您有一个边缘连接产品和注释,并且总是按时间顺序插入,则可以执行以下操作:
SELECT Name, last(out()).Message, last(out()).Date FROM Product
我已经创建了一个小的db测试
create class Product extends V
create property Product.name String
create class Comments extends V
create property Comments.message String
create property Comments.date DATE
create class Product_Comments extends E
insert into Product(name) values ("Product 1") // 12:0
insert into Product(name) values ("Product 2") // 12:1
insert into comments(message,date) values ("message 1","2016-01-01") //13:0
insert into comments(message,date) values ("message 2","2016-02-01") //13:1
insert into comments(message,date) values ("message 3","2016-01-15") //13:2
insert into comments(message,date) values ("message 4","2016-02-14") //13:3
create edge Product_Comments from 12:0 to 13:0
create edge Product_Comments from 12:0 to 13:1
create edge Product_Comments from 12:1 to 13:2
create edge Product_Comments from 12:1 to 13:3
您可以使用此查询
SELECT name, $checks[0].date as date , $checks[0].message as message FROM Product
let $a = ( select expand(out("Product_Comments")) from $parent.$current),
$checks= ( select date, message from $a where date in ( select max(date) from $a))
希望有帮助。您有一些边缘可以将产品与评论链接起来,或者您正在使用链接列表?您使用的OrientDb ara的哪个版本?我正在使用edge将产品链接到评论,这是2.1.11版社区