簡體   English   中英

orientdb sql查詢選擇邊和頂點字段屬性。

[英]orientdb sql query to select edge and vertex fields property.

我確實有以下數據庫結構。

用戶 - >評論 - >產品

一個。 用戶和產品是包含一些信息等的頂點:user_name,product_name和.... b。 comment是包含注釋和創建/修改日期的邊緣。

什么是sql查詢可能看起來像是為了顯示以下結果。

注意:我必須顯示可能有或沒有評論的所有產品。

  1. product_name,user_name,comment,comment_created_date,comment_modified_date
  2. product_name,user_name,'','',''
  3. product_name,user_name,comment,comment_created_date,comment_modified_date
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,然后使用letunionall()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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM