简体   繁体   English

orientdb sql查询选择边和顶点字段属性。

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

I do have following database structure. 我确实有以下数据库结构。

users -> comment -> products 用户 - >评论 - >产品

a. 一个。 users and products are the vertexes that contain some info etc: user_name, product_name and .... b. 用户和产品是包含一些信息等的顶点:user_name,product_name和.... b。 comment is the edge that contains comment and created/modified date. comment是包含注释和创建/修改日期的边缘。

what is the sql query may look like in order to show the following result. 什么是sql查询可能看起来像是为了显示以下结果。

Note: i have to show all of the products that may have or no have comment. 注意:我必须显示可能有或没有评论的所有产品。

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

If the above is your situation, I believe the query you're looking for is something like: 如果您的情况如上,我相信您正在寻找的查询类似于:

select *, expand(inE('Comment')) from Product

UPDATE: 更新:

It's not very pretty, but as a workaround you could use: 它不是很漂亮,但作为一种解决方法,您可以使用:

select *, inE('Comment').include('comment', 'createDate', 'modifiedDate') from Product

you cannot "join" classes/tables when querying. 查询时不能“加入”类/表。 instead, merge the result sets -> start from the edge class for Product s with Comment s, then use let and unionall() to add the non- Comment ed Product s before expand() ing: 相反,合并结果集 - >从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)

note that in the result set you will have the @CLASS field fed with null s from the first query (ie, from the $a result set) and with Product from the second query (the $b result set) 请注意,在结果集中,您将从第一个查询(即,从$a结果集)和第二个查询中的Product$b结果集)中获取带有null@CLASS字段

using @vitorenesduarte schema the following query may fit the current requirement 使用@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