我有兩個頂點類:Product,Comment。每個產品可以有很多評論。評論有兩個屬性:日期和消息。OrientDB查詢產品的最後評論
{}產品 - > {}評論
我需要編寫檢索所有的產品與他們最後的評論信息的查詢。 Product Message Date A the last comment 01/01/2016 B xxx 22/01/2011 ...
我找不到這類查詢的任何文檔。
我有兩個頂點類:Product,Comment。每個產品可以有很多評論。評論有兩個屬性:日期和消息。OrientDB查詢產品的最後評論
{}產品 - > {}評論
我需要編寫檢索所有的產品與他們最後的評論信息的查詢。 Product Message Date A the last comment 01/01/2016 B xxx 22/01/2011 ...
我找不到這類查詢的任何文檔。
我創建了一個小的分貝測試
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))
希望它有幫助。
如果您無法連接產品和評論的邊緣,你總是按時間順序插入,你可以這樣做:
SELECT Name, last(out()).Message, last(out()).Date FROM Product
您有一些將產品鏈接到評論的邊緣,或者您正在使用Linklist? 你使用什麼版本的OrientDb ara? –
我正在使用邊緣鏈接產品評論,這是版本2.1.11社區 –