[英]orientdb sql query to select edge and vertex fields property.
我確實有以下數據庫結構。
用戶 - >評論 - >產品
一個。 用戶和產品是包含一些信息等的頂點:user_name,product_name和.... b。 comment是包含注釋和創建/修改日期的邊緣。
什么是sql查詢可能看起來像是為了顯示以下結果。
注意:我必須顯示可能有或沒有評論的所有產品。
create class User extends V
create property User.name string
create class Product extends V
create property Product.name string
create class Comment extends E
create property Comment.comment string
create property Comment.createDate datetime
create property Comment.modifiedDate datetime
create vertex User set name = 'u1' # 12:0
create vertex Product set name = 'p1' # 13:0
create vertex Product set name = 'p2' # 13:1
create edge Comment from #12:0 to #13:0 set comment = 'nice product', createDate = sysdate()
如果您的情況如上,我相信您正在尋找的查詢類似於:
select *, expand(inE('Comment')) from Product
更新:
它不是很漂亮,但作為一種解決方法,您可以使用:
select *, inE('Comment').include('comment', 'createDate', 'modifiedDate') from Product
查詢時不能“加入”類/表。 相反,合並結果集 - >從Product
s的edge類開始,使用Comment
s,然后使用let
和unionall()
在expand()
之前添加非Comment
ed Product
:
select expand($c)
let $a = (select in.name as name, out.name as User, comment, createDate, modifiedDate from Comment),
$b = (select from Product where in_Comment is null),
$c = unionall($a, $b)
請注意,在結果集中,您將從第一個查詢(即,從$a
結果集)和第二個查詢中的Product
( $b
結果集)中獲取帶有null
的@CLASS
字段
使用@vitorenesduarte模式,以下查詢可能符合當前要求
select name AS product_name,in(comment).name
AS user_name,inE(comment).comment
AS comment,inE(comment).createDate
AS comment_created_date,inE(comment).modifiedDate
AS comment_modified_date from product
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.