-->
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: Problem to make JP-QL query - help!
PostPosted: Mon Sep 20, 2010 4:42 pm 
Newbie

Joined: Mon Sep 20, 2010 4:33 pm
Posts: 1
Hi!

I read bunch of examples, but I have troubles to "translate" my SQL query to JPQL query. SQL query is something like this:
Code:
select store.id, ifnull(sum(stock.number),0)-ifnull(sum(storeorder.number),0) from item
join orderitem on (item.id=orderitem.iditem)
join storeorder on (orderitem.id=storeorder.idorderitem)
join store on (storeorder.idstore=store.id)
left join stock on (item.id=stock.iditem)
where item.id = '71' -- This could be parameterized
group by store.id;


In the Stock table new records are added when new items are added to some Store. When Item is sold, then record to the StoreOrder table is added. I want to get current stock for every store for given itemID.

For example, result set would be:
Code:
Store 1         33
Store 2         5
Store 3        3
Store 4       66


Any help? :)


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.