How to write a query in OrientDB for JOIN + Aggregation

862 views
Skip to first unread message

Hung Tran Dinh

unread,
May 29, 2013, 12:18:39 AM5/29/13
to orient-...@googlegroups.com
hi,

I don't know how to write an equivalent query in OrientDB to perform the logic as follows

1. SELECT distinct (product)
    FROM Order order LEFT JOIN order.Lines line LEFT JOIN line.Product product

2. SELECT product, count(*) 
    FROM Order order LEFT JOIN order.Lines line LEFT JOIN line.Product product
    GROUP BY product

3. SELECT product, sum(line.Qty * line.Price)
    FROM Order order LEFT JOIN order.Lines line LEFT JOIN line.Product product
    GROUP BY product

(In the samples above, I have used HQL instead of SQL)
   
Any help would be very appreciated!

Hung Tran

Luca Garulli

unread,
May 31, 2013, 10:09:22 AM5/31/13
to orient-database
Hi,
you should create a link between Order and Product, then you can traverse the relations using the dot (.) notation, like:

select expand(products) from Order

if you've create "products" properties as LINKSET against Product. Or, better again, model your domain as a graph.

Lvc@




Hung Tran

--
 
---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages