-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: [Criteria query] how to adapt the following SQL query?
PostPosted: Mon Jan 19, 2009 12:17 pm 
Newbie

Joined: Tue Nov 20, 2007 12:15 pm
Posts: 10
Using the standard Order/Bids relationship (an Order has 0-* Bids) as an example: obtain a list of Orders sorted by most to least Bids. How can this be done in Criteria?

Code:
select
    orders.*
from
    (
        select
            o.order_id,
            count( b.bid_id ) as count_bids
        from
            order_table o
        left join
            bids_table b
                on o.order_id = b.order_id
        group by
            o.order_id
        order by
            count_bids
    ) as ordered
join
    order_table orders
        on orders.order_id = ordered.order_id


thanks anyone.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.